Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple issues related to reconnect #1367

Merged
merged 1 commit into from Nov 29, 2023
Merged

Fix multiple issues related to reconnect #1367

merged 1 commit into from Nov 29, 2023

Conversation

PhilipRoman
Copy link
Collaborator

@PhilipRoman PhilipRoman commented Nov 1, 2023

This fixes some issues regarding reconnect.
Previously there was a massive thread leak caused by repeatedly reconnecting, this no longer happens (tested manually with VisualVM profiler). Also race conditions with null pointer exceptions in multiple places.
No exceptions, leaked threads, deadlocks or other problems found after running 100000 iterations of reconnecting with various delays inbetween. No new test failures (I think one existing failure might be fixed but not sure yet)

To be honest this code is a multithreading nightmare but the general idea of this PR is to make sure that there may exist only one read/write thread per WebSocketClient and it can never be leaked due to "interrupt+join" combination before each reassignment.

I have also removed some unneeded assignments to null as they can cause a race condition where thread is set to null between if(thread != null) and thread.interrupt() - this problem cannot be solved simply by locking, as we can end up in a deadlock.

Please review and run your own test programs with this version
@Xander-Polishchuk

Meanwhile I will also continue manual testing and maybe leave a stability test to run for several days

Fixes #1364

@PhilipRoman PhilipRoman linked an issue Nov 1, 2023 that may be closed by this pull request
@PhilipRoman PhilipRoman merged commit 8834112 into master Nov 29, 2023
3 of 4 checks passed
@PhilipRoman PhilipRoman deleted the reconnect-fix branch December 16, 2023 10:45
@marci4 marci4 added this to the Release 1.5.5 milestone Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE during reconnect
2 participants