Subscriber not cleaning resources when subscribing to non-existing subscription (Subscriber.subStub and StreamingSubscriberConnection.messageDispatcher) #315
Labels
api: pubsub
Issues related to the googleapis/java-pubsub API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
🚨
This issue needs some love.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Some resources (Subscriber.subStub and StreamingSubscriberConnection.messageDispatcher) seem not to be cleaned up when Subscriber fails trying to subscribe to non-existing subscription when using shared
ScheduledThreadPoolExecutor
. As a result executor work queue grows up in time using memory and cpu.Attached code fragment below is an example of how to reproduce the issue, scenario:
I analysed the leak a bit further and I noticed that Watchdog and StreamingSubscriberConnection.messageDispatcher tasks are being queued in ScheduledThreadPoolExecutor. Here is why:
stopAllStreamingConnections()
andshutdownBackgroundResources()
This results in
How to fix it ?
I have prepared sample commit with fix that does the cleanup but I guess it may break some internal stuff, so I am sharing this to start discussion and find correct solution :)
Environment details
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment 18.9 (build 11.0.5+10)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10, mixed mode)
Steps to reproduce
io.grpc.StatusRuntimeException: NOT_FOUND: Resource not found (resource=nonExistingSubscriptionName)
Code example (Kotlin)
The text was updated successfully, but these errors were encountered: