Skip to content

Driver and agent leak file handles when an exception interrupts a stream #10

Open

Description

@lgnap

Contexte

Several file streams in the driver and agent modules are opened and closed by hand instead of with try-with-resources. If anything throws between the open and the .close(), the handle leaks. On Windows a leaked handle keeps the file locked, which then breaks later writes/deletes of the same pack folder (the write-path this fork focuses on).

Description

Wrap every manually closed stream in try-with-resources so the handle is released even when an exception is thrown mid-way. Pure robustness change, no behaviour change on the happy path.

Fichiers concernes

  • driver/src/main/java/studio/driver/fs/CipherUtils.java:56-64 (addBootFileV2) — FileInputStream riFis and FileOutputStream btFos closed by hand
  • driver/src/main/java/studio/driver/raw/RawStoryTellerAsyncDriver.java:516-518 (dumpSector) — FileOutputStream sectorOutputStream closed after writeByteBufferToStream, which can throw
  • agent/src/main/java/studio/agent/UnofficialMetadataAdvice.java:59-62 — FileOutputStream fos around a Base64.decode + write
  • driver/src/test/java/studio/driver/fs/CipherUtilsStreamLifecycleTest.java (new) — forces a failure after the stream is opened and asserts the file is not locked / handle released
  • Existing patterns to reuse: driver/src/test/java/studio/driver/fs/FilesWalkResourceLeakTest.java, web-ui/src/test/java/studio/webui/service/ConversionStreamLifecycleTest.java

Plan d'implementation

  1. CipherUtils.addBootFileV2: try-with-resources on both streams.
  2. RawStoryTellerAsyncDriver.dumpSector: try-with-resources on sectorOutputStream.
  3. UnofficialMetadataAdvice: try-with-resources on fos.
  4. Add a stream-lifecycle test for addBootFileV2 (e.g. truncated/unreadable ri file) that asserts the boot file can be deleted afterwards, which is the observable Windows symptom.
  5. mvn -pl driver,agent test green.

Criteres d'acceptation

  • No manual .close() left on these three sites; all use try-with-resources
  • New test fails on the old code (handle leaked) and passes on the fix
  • mvn -pl driver,agent test green on Ubuntu and Windows CI
  • git diff --exit-code clean after the build (no tracked file rewritten)

Complexite

S

Activity

  1. lgnap commented on Sep 11, 2026

    @lgnap
    OwnerAuthor

    Prise en charge par Claude Code (instance tuxedo:40112:d397e957, branche fix/issue-10-driver-stream-leaks).

  2. lgnap commented on Sep 11, 2026

    @lgnap
    OwnerAuthor

    Implemented in antoinevalentinHA#56 (branch fix/issue-10-driver-stream-leaks).

    • try-with-resources on CipherUtils.addBootFileV2, RawStoryTellerAsyncDriver.dumpSector, UnofficialMetadataAdvice
    • new BootFileStreamLifecycleTest (5 tests) pinning the nominal contract of addBootFileV2; the failure path is not injectable from outside (documented in the test javadoc), so this is a fix by inspection
    • CI green on Ubuntu, Windows and Web UI; git diff --exit-code clean

    Awaiting review/merge by the upstream owner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions