Repository navigation
Commit 600f903
authored
fix(inspector): release the frontend's resources when DevTools disconnects (#516)
* fix(inspector): release the frontend's resources when DevTools disconnects
Since #390 closes the client channel on EOF, nothing told
JsV8InspectorClient: sender_ kept the closed channel, so every later CDP
message (console.log, scriptParsed, ...) failed with
"InspectorServer::Send error: Operation canceled". The departed
frontend's session also stayed alive with its breakpoints and enabled
domains, so a pause after disconnect (or a disconnect while paused) left
the app frozen with nobody to resume it.
InspectorServer:
- Track each client as a Connection with an id and its own serial queue.
Closing is idempotent and reports onClientDisconnected(id); the sender
drops messages once closed, and ECANCELED from writes queued before
the close is no longer logged.
- Replace the self-referencing __block read handler (an ARC retain cycle
that leaked the block and channel per connection) with a read loop
that accumulates each frame until done.
- Set SO_NOSIGPIPE on client sockets.
JsV8InspectorClient:
- On disconnect, clear the sender (ignoring stale connection ids) and
reset the frontend's state: IO streams, tracing, worker sessions, and
the main session.
- Reset the main session through the message queue instead of taking the
Locker on the socket thread, which blocked while the isolate was paused.
Inside the pause loop the reset resumes and skips further pauses, and
the session is swapped by the next drain once the loop has unwound.
- Only reset on connect when replacing a still-attached frontend.
- Open the listening socket once: the CLI re-posts AttachRequest every
few seconds until it sees the port, and each post used to open another
listener on the next port.
* fix(inspector): serialize frontend connect/disconnect, one client at a time
Each connection runs its callbacks on its own queue, so an old
connection's disconnect could interleave with the next connection's
connect: the new frontend saw no attached frontend, skipped its reset,
and its Debugger.enable / Tracing.start / IO streams were then wiped by
the old disconnect's late cleanup. Serialize both handlers with a
dedicated lifecycle mutex (not senderMutex_, which RegisterWorkerTarget
takes after workerTargetsMutex_).
The server now accepts one client at a time: a new client closes the
previous one, under a lock held across both callbacks so back-to-back
accepts cannot hand out senders in the opposite order. A session reset
also drops the departing frontend's still-queued messages, so their
replies (whose ids may collide) never reach the next frontend.
* fix(inspector): drop messages from a connection after it is replaced
Closing a replaced connection does not cancel a read handler that has
already assembled a message, so the old frontend's last command could
still be dispatched to the new frontend's session, and its reply sent to
the new frontend. Message callbacks now carry the connection id, and
onFrontendMessageReceived drops messages from a connection that is no
longer current. The check and the enqueue run under the lifecycle mutex,
so a concurrent takeover's reset drops anything queued before it.
* fix(inspector): keep a replaced frontend's output away from its successor
A command already executing when a new frontend takes over replied
through the current sender, so the new frontend received the old one's
reply. The main session now has its own binding: all of its output
(V8 replies and events, JS-domain replies, __inspectorSendEvent, Target
events) goes through notify() to the connection it serves. A sync
message, queued on every connect and disconnect ahead of the new
frontend's messages, rebinds it on the main thread and replaces the
session first if it served another connection. Inside the pause loop
only a needed replacement is deferred.
Worker sessions get the same guarantee through a frontend generation,
bumped atomically with the sender swap whenever a frontend goes away or
is replaced. A worker session records it when created, reset or
registered, and output with a stale generation is dropped.
AnnounceWorkerTargets bails once a frontend change cleared auto-attach,
so it cannot mark workers announced that the next frontend never saw,
and Target.setAutoAttach from a replaced frontend no longer turns
auto-attach on for its successor.
Takeover and onClientConnected now run on the accept handler, which is
serial, so back-to-back accepts take over in accept order.
Also initialize isWaitingForDebugger_, hasScheduledDebugBreak_ and
terminated_, which were read before ever being set.1 parent 20935bd commit 600f903
6 files changed
Lines changed: 472 additions & 135 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
14 | 27 | | |
15 | | - | |
| 28 | + | |
16 | 29 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | 33 | | |
24 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 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 | + | |
8 | 121 | | |
9 | | - | |
10 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
11 | 125 | | |
12 | 126 | | |
13 | 127 | | |
| |||
31 | 145 | | |
32 | 146 | | |
33 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
34 | 152 | | |
35 | 153 | | |
36 | 154 | | |
| |||
43 | 161 | | |
44 | 162 | | |
45 | 163 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
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 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
95 | 168 | | |
96 | | - | |
97 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
98 | 184 | | |
| 185 | + | |
99 | 186 | | |
100 | | - | |
101 | 187 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
107 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
108 | 206 | | |
109 | 207 | | |
110 | 208 | | |
| |||
121 | 219 | | |
122 | 220 | | |
123 | 221 | | |
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 | 222 | | |
0 commit comments