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: Fix a leak of WebSocketClients. #2051

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

bgrozev
Copy link
Member

@bgrozev bgrozev commented Sep 15, 2023

Every time we establish an active WS to another relay we create a new
WebSocketClient instance. This comes with its own QueuedThreadPool with 8 threads
and if we lose the reference without calling stop() it leaks.

When the existing web socket closing arrives before the signaling that
expires the relay, we try do WebSocketClient.stop() and then
doConnect(). The call to stop() can take a while, and if in the meantime
the relay is expired in signaling we end up running doConnect() on
an expired relay. In this case we create a new WebSocketClient, which
is never stopped.

This fix uses a single WebSocketClient instance shared between all
relays, and does not attempt to re-connect if the reason for the
disconnect is RELAY_CLOSED. It re-uses the "webSocket: ColibriWebSocket"
field for sockets created both actively and passively.

Every time we establish an active WS to another relay we create a new
WebSocketClient instance. This comes with its own QueuedThreadPool with 8 threads
and if we lose the reference without calling stop() it leaks.

When the existing web socket closing arrives before the signaling that
expires the relay, we try do WebSocketClient.stop() and then
doConnect(). The call to stop() can take a while, and if in the meantime
the relay is expired in signaling we end up running doConnect() on
an expired relay. In this case we create a new WebSocketClient, which
is never stopped.

This fix uses a single WebSocketClient instance shared between all
relays, and does not attempt to re-connect if the reason for the
disconnect is RELAY_CLOSED. It re-uses the "webSocket: ColibriWebSocket"
field for sockets created both actively and passively.
@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Merging #2051 (a102e43) into master (8983b11) will increase coverage by 0.13%.
The diff coverage is 10.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2051      +/-   ##
============================================
+ Coverage     42.41%   42.55%   +0.13%     
- Complexity     1673     1682       +9     
============================================
  Files           325      325              
  Lines         17155    17142      -13     
  Branches       2255     2253       -2     
============================================
+ Hits           7277     7294      +17     
+ Misses         9168     9132      -36     
- Partials        710      716       +6     
Files Changed Coverage
...g/jitsi/videobridge/relay/RelayMessageTransport.kt 10.00%

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8983b11...a102e43. Read the comment docs.

@bgrozev bgrozev merged commit 37da7e1 into jitsi:master Sep 25, 2023
3 of 4 checks passed
@bgrozev bgrozev deleted the fix-web-socket-client-leak branch May 23, 2024 13:35
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