You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing a new application that needs to connects to different Ably clients.
Each client will use a different token and subscribe to a different channel.
The channels have some limited life, and when some certain message is received, I want to unsubscribe the channel.
As soon as the message of unsubscribing the channel, also the client connection is closed.
The main problem is that all the threads relative to the client/channel are still actives, although I don't think they are doing anything.
Since, the application should run continuously adding new channels, I would like to know if there is clean way of closing all the threads after the channel received the closure message.
Hey @mighelone, thanks for reporting this! We're just looking into this now, are you able to provide some info on what the names of the active threads are and which version of the library you're using?
I've had a look into this for you and I think I've found the issue you're running into - just a couple of questions to confirm my suspicions:
I was wondering how you configure the AblyRealtime object - do you use the autoConnect option in ClientOptions at all? The default is true, so if you haven't specifically disabled it in your ClientOptions, then there will be an autoconnect as part of the constructor.
Also, after constructing the AblyRealtime object, do you subsequently make an explicit call to connect()?
I've managed to reproduce the issue on 1.2.25 and spotted a bug in situations where the autoConnect option and a call to connect() explicitly are used together. This causes two connection attempts under the hood that can interfere with each other and this can result in various stale threads hanging around even after the connection is closed.
If you are doing both, you should be able to avoid this issue by either using the autoConnect option or an explicit call to connect().
In the meantime, we'll look deeper into the underlying issue and look at how we can address it - the autoconnect and explicit connect call shouldn't be interfering with each other, in any case!
When I run this myself on ably-java 1.2.18 it doesn't list any ably-related threads. I have also tried using an authCallback and got the same result. Would you be able to provide a minimal repro script?
Just for clarity, I am connecting to a cluster managed from one of your customers, and I need to specify the fallbackHosts and the environment in the ChannelOptions.
When I run this code, the execution process hangs indefinitely and I have to manually stop.
If I run the same code, using the channel here https://ably.com/hub/ably-coindesk/bitcoin, everything works fine, and the application exits normally.
The only difference I can notice between the two runs in terms of threads is:
In the hanging application:
Thread :Thread[WebSocketWriteThread-38,5,main]:state:WAITING ,
while in the completed application:
Thread :Thread[WebSocketWriteThread-29,5,main]:state:RUNNABLE
@mighelone I've been asked to look at this as @owenpearson and @AndyTWF are both busy on other things. I'll admit, I'm struggling to try to work out what we're trying to debug and investigate here. I think we need more information from you, please.
First, and foremost, verbose log output - including the messages you're printing to System.out, ideally with timestamps.
In respect of:
When I run this code, the execution process hangs indefinitely and I have to manually stop.
I'm unclear as to when in your app's execution this is happening. We need more detail here, which the verbose logs will help with.
Also, could you please provide us with the concrete values being returned by your ChannelName API, as this is all very abstract right now and difficult to emulate at our end. There's not much to go on from our side. Ideally it would be good to see some self-contained code without external dependencies that are invisible to us.
If you need to share anything (e.g. sensitive/private) in a venue outside of this public GitHub issue then we can get that arranged.
Activity
sync-by-unito commentedon Feb 8, 2023
➤ Automation for Jira commented:
The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3327
owenpearson commentedon Feb 8, 2023
Hey @mighelone, thanks for reporting this! We're just looking into this now, are you able to provide some info on what the names of the active threads are and which version of the library you're using?
mighelone commentedon Feb 8, 2023
Hey @owenpearson , thanks for the replay.
The version of the APIs are 1.2.18, I just noticed that some minor updates have been released (1.12.25).
Concerning the threads, follows a partial list of the main threads existing, after closing the ably realtime client:
AndyTWF commentedon Feb 8, 2023
Hi @mighelone, thanks for the extra information!
I've had a look into this for you and I think I've found the issue you're running into - just a couple of questions to confirm my suspicions:
AblyRealtimeobject - do you use theautoConnectoption inClientOptionsat all? The default istrue, so if you haven't specifically disabled it in yourClientOptions, then there will be an autoconnect as part of the constructor.AblyRealtimeobject, do you subsequently make an explicit call toconnect()?I've managed to reproduce the issue on 1.2.25 and spotted a bug in situations where the
autoConnectoption and a call toconnect()explicitly are used together. This causes two connection attempts under the hood that can interfere with each other and this can result in various stale threads hanging around even after the connection is closed.If you are doing both, you should be able to avoid this issue by either using the
autoConnectoption or an explicit call toconnect().In the meantime, we'll look deeper into the underlying issue and look at how we can address it - the autoconnect and explicit connect call shouldn't be interfering with each other, in any case!
mighelone commentedon Feb 8, 2023
Hey @AndyTWF thanks for the update.
I don't call directly the connect() option.
Here are the basic steps of the ably client creation:
owenpearson commentedon Feb 9, 2023
Hey @mighelone I've tried a couple of different setups but haven't been able to reproduce this issue so far.
Here's a simple script which closes a realtime instance upon receipt of a channel message, and then prints out all threads after waiting for 2s.
When I run this myself on ably-java 1.2.18 it doesn't list any ably-related threads. I have also tried using an authCallback and got the same result. Would you be able to provide a minimal repro script?
mighelone commentedon Feb 10, 2023
Hey @owenpearson ,
Here you can find a simple example of my code:
Just for clarity, I am connecting to a cluster managed from one of your customers, and I need to specify the fallbackHosts and the environment in the ChannelOptions.
When I run this code, the execution process hangs indefinitely and I have to manually stop.
If I run the same code, using the channel here https://ably.com/hub/ably-coindesk/bitcoin, everything works fine, and the application exits normally.
The only difference I can notice between the two runs in terms of threads is:
In the hanging application:
Thread :Thread[WebSocketWriteThread-38,5,main]:state:WAITING ,
while in the completed application:
Thread :Thread[WebSocketWriteThread-29,5,main]:state:RUNNABLE
QuintinWillison commentedon Feb 14, 2023
@mighelone I've been asked to look at this as @owenpearson and @AndyTWF are both busy on other things. I'll admit, I'm struggling to try to work out what we're trying to debug and investigate here. I think we need more information from you, please.
First, and foremost, verbose log output - including the messages you're printing to
System.out, ideally with timestamps.In respect of:
I'm unclear as to when in your app's execution this is happening. We need more detail here, which the verbose logs will help with.
Also, could you please provide us with the concrete values being returned by your
ChannelNameAPI, as this is all very abstract right now and difficult to emulate at our end. There's not much to go on from our side. Ideally it would be good to see some self-contained code without external dependencies that are invisible to us.If you need to share anything (e.g. sensitive/private) in a venue outside of this public GitHub issue then we can get that arranged.
ttypic commentedon Apr 23, 2024
Hey @mighelone,
Just wanted to check in on this issue since there hasn't been any activity for a while. We're closing it since there's been no recent discussion.
If you still feel this needs attention or have any updates, please reopen it, and we can keep the conversation going!