Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 29, 2025

The asDeferred() extension function subscribed to a Mono but didn't capture the Subscription reference, preventing proper cleanup and garbage collection after completion or error.

Changes:

  • Store Subscription reference in subscriber state
  • Clear reference in onComplete() and onError() to allow GC
  • Use stored field consistently in cancellation handler

Before:

override fun onSubscribe(s: Subscription) {
    deferred.invokeOnCompletion {
        if (deferred.isCancelled) s.cancel()
    }
    s.request(Long.MAX_VALUE)
}

After:

private var subscription: Subscription? = null

override fun onSubscribe(s: Subscription) {
    subscription = s
    deferred.invokeOnCompletion {
        if (deferred.isCancelled) subscription?.cancel()
    }
    s.request(Long.MAX_VALUE)
}

override fun onComplete() {
    deferred.complete(value ?: throw NoSuchElementException(...))
    value = null
    subscription = null  // Allow GC
}

Addresses resource leak where subscriber held subscription reference indefinitely after terminal events.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 29, 2025 21:51
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 29, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repo.slne.dev
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:&#43;HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix subscription disposal in Redis migration feedback Fix subscription disposal in Mono.asDeferred() extension Dec 29, 2025
Copilot AI requested a review from twisti-dev December 29, 2025 21:53
@twisti-dev twisti-dev closed this Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants