Skip to content

Opt-in resource leak detector (log-only, no auto-close) #45

Description

@OmarAlJarrah

Problem

A caller who forgets to close a response/stream gets no signal until something breaks.

Proposed change

Add an opt-in leak detector that logs a WARN when a closeable becomes phantom-reachable without having been closed. Obtain java.lang.ref.Cleaner reflectively (cached by lazy) so the same Java-8 bytecode uses it on JDK 9+ and no-ops on 8. Reuse the existing closed flag as the "was it closed?" signal. Gate behind a system property; default off. Do not auto-close — detection only (auto-closing a caller-owned resource is the hazard we deliberately avoid).

Prior art: openai-java's PhantomReachable uses the reflective-Cleaner technique (Apache-2.0 — attribute the lifted util).

Acceptance

  • WARN on unclosed phantom-reachable closeable
  • No-op on Java 8
  • Test uses a GC-poll loop (not a fixed sleep)

Priority: low · Effort: medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsdk-coresdk-core toolkit

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions