Commit 6abe34d
committed
Fix deadloack introduced in #402
This PR fixes the deadlock introduced in #402. The deadlock was occurring
because the forwardWebSocketData function was holding a lock on the
subscription map (in the listenWebSocket goroutine) while Unsubscribe was
blocked attempting to aquire the same lock. The forwardWebSocketData function
was also blocked attempting to send data on the interfaceChan channel, which
had no readers in the test being run.
After fixing the locking (by making sure the lock isn't held when
forwardDataFunc is called), a race condition cropped up between sending on
interfaceChan (in forwardWebSocketData) and closing interfaceChan in
Unsubscribe. This was fixed by making the listenWebSocket goroutine the "owner"
of the interfaceChan channel -- it is now the only goroutine that sends on and
closes the channel. Other goroutines singal interfaceChan should be closed by
setting `_hasBeenUnsubscribed` on the channel, which is protected by a
short-held lock.
Note that there's a similar data race involving isClosing on webSocketClient.
isClosing is set when Close is called (while holding a lock) but read in
listenWebSocket without a lock. A separate PR will fix this race (so the
`-race` flag can be added when running tests).1 parent 5b0aabc commit 6abe34d
4 files changed
Lines changed: 73 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
16 | 27 | | |
| 28 | + | |
17 | 29 | | |
18 | 30 | | |
19 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
20 | 49 | | |
21 | 50 | | |
22 | 51 | | |
| |||
26 | 55 | | |
27 | 56 | | |
28 | 57 | | |
29 | | - | |
| 58 | + | |
30 | 59 | | |
31 | 60 | | |
32 | 61 | | |
| |||
37 | 66 | | |
38 | 67 | | |
39 | 68 | | |
40 | | - | |
41 | | - | |
| 69 | + | |
42 | 70 | | |
43 | 71 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 72 | | |
48 | 73 | | |
49 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
50 | 91 | | |
51 | 92 | | |
52 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
117 | 128 | | |
118 | 129 | | |
119 | 130 | | |
| |||
139 | 150 | | |
140 | 151 | | |
141 | 152 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | | - | |
149 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
150 | 160 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
155 | 165 | | |
156 | 166 | | |
157 | | - | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
0 commit comments