ably-java icon indicating copy to clipboard operation
ably-java copied to clipboard

Quick calls to connect() results in thread leaks

Open AndyTWF opened this issue 3 years ago • 1 comments

Discovered inadvertently during the investigation of https://github.com/ably/ably-java/issues/917.

If you use the autoconnect option in ClientOptions and also call connect on the ably instance, a race condition exists whereby threads are leaked from the underlying websocket handler.

This is because starting connections discards the current transport, calling transport.close(). The underlying websocket library only cleans up threads properly if the write thread (which is started by the read thread) isn't null.

With quick calls to connect, you can end up in a case where the write thread isn't yet started. This means that when the transport is closed, the read thread is left running, the write thread gets created - and neither can be cleaned up.

The issue is complicated by the fact that connecting is an asynchronous state change.

┆Issue is synchronized with this Jira Task by Unito

AndyTWF avatar Feb 09 '23 10:02 AndyTWF

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3329

sync-by-unito[bot] avatar Feb 09 '23 10:02 sync-by-unito[bot]