Commit 6edb9f1
authored
[ZEPPELIN-6260] Fix memory leak in WebSocket watcher connections
### What is this PR for?
This PR fixes a memory leak issue where WebSocket connections that are switched to watcher mode are never removed from the watcherSockets queue when the connection is closed. This causes the queue to grow indefinitely, leading to increased memory
usage over time and potential OutOfMemoryError in long-running Zeppelin servers.
### What type of PR is it?
Bug Fix
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-6260
### How should this be tested?
Steps to reproduce the issue:
1. Open a WebSocket connection to Zeppelin
2. Send a WATCHER message to switch the connection to watcher mode
3. Close the connection
4. The connection remains in watcherSockets queue indefinitely
Verification after fix:
- Unit tests have been added to verify the fix:
- removeWatcherConnectionCleansQueue: Basic functionality test
- removeWatcherConnectionWithMultipleWatchers: Tests selective removal
- removeWatcherConnectionConcurrentTest: Tests thread safety
- switchConnectionToWatcherAndRemove: Tests complete lifecycle
### Screenshots (if appropriate)
N/A
### Questions:
- Does the license files need update? No
- Is there breaking changes for older versions? No
- Does this needs documentation? No
### Description of changes:
1. Added removeWatcherConnection() method to ConnectionManager to safely remove connections from the watcherSockets queue
2. Modified NotebookServer.removeConnection() to call removeWatcherConnection() when any connection is closed
3. Added debug logging to track watcher connection removal
4. Added comprehensive unit tests including concurrent access scenarios
The fix is minimal and safe:
- The ConcurrentLinkedQueue.remove() operation is safe even if the element doesn't exist
- The synchronization block is very short, minimizing performance impact
- The approach ensures no watcher connections are leaked, regardless of how they were closed
### Related observations:
During the investigation, I noticed that broadcastToWatchers() doesn't remove watchers when IOException occurs. This could cause performance degradation as closed connections would repeatedly fail. However, this is a separate issue and should be
addressed in a different PR to keep this fix focused.
Closes #5001 from renechoi/ZEPPELIN-6260-fix-watcher-memory-leak.
Signed-off-by: Philipp Dallig <philipp.dallig@gmail.com>1 parent 1a66333 commit 6edb9f1
File tree
3 files changed
+120
-0
lines changed- zeppelin-server/src
- main/java/org/apache/zeppelin/socket
- test/java/org/apache/zeppelin/socket
3 files changed
+120
-0
lines changedLines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
178 | 186 | | |
179 | 187 | | |
180 | 188 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
| 506 | + | |
506 | 507 | | |
507 | 508 | | |
508 | 509 | | |
| |||
Lines changed: 111 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
21 | 31 | | |
22 | 32 | | |
23 | 33 | | |
| 34 | + | |
24 | 35 | | |
25 | 36 | | |
26 | 37 | | |
| |||
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
60 | 171 | | |
0 commit comments