File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,9 @@ class DevHandler {
162
162
);
163
163
}
164
164
}
165
+ _logger.fine (
166
+ 'Sent request to $successfulSends clients out of ${_injectedConnections .length } total connections' ,
167
+ );
165
168
return successfulSends;
166
169
}
167
170
@@ -392,8 +395,12 @@ class DevHandler {
392
395
_injectedConnections.remove (injectedConnection);
393
396
final connection = appConnection;
394
397
if (connection != null ) {
395
- _appConnectionByAppId.remove (connection.request.appId);
396
- final services = _servicesByAppId[connection.request.appId];
398
+ final appId = connection.request.appId;
399
+ final services = _servicesByAppId[appId];
400
+ // WebSocket mode doesn't need this because WebSocketProxyService handles connection tracking and cleanup
401
+ if (! useWebSocketConnection) {
402
+ _appConnectionByAppId.remove (appId);
403
+ }
397
404
if (services != null ) {
398
405
if (services.connectedInstanceId == null ||
399
406
services.connectedInstanceId == connection.request.instanceId) {
Original file line number Diff line number Diff line change @@ -258,11 +258,31 @@ class WebSocketProxyService implements VmServiceInterface {
258
258
_logger.fine (
259
259
'Removed connection: $connectionId (remaining: $_activeConnectionCount )' ,
260
260
);
261
+ _logger.fine (
262
+ 'Current tracked connections: ${_appConnectionDoneSubscriptions .keys .toList ()}' ,
263
+ );
261
264
262
- // Only destroy the isolate if there are no more active connections
265
+ // Instead of destroying the isolate immediately, check if there are still
266
+ // clients that can receive hot reload requests
263
267
if (_activeConnectionCount <= 0 ) {
264
- _logger.fine ('No more active connections, destroying isolate' );
265
- destroyIsolate ();
268
+ // Double-check by asking the sendClientRequest callback how many clients are available
269
+ final actualClientCount = sendClientRequest ({'type' : 'ping' });
270
+ _logger.fine (
271
+ 'Actual client count from sendClientRequest: $actualClientCount ' ,
272
+ );
273
+
274
+ if (actualClientCount == 0 ) {
275
+ _logger.fine (
276
+ 'No clients available for hot reload, destroying isolate' ,
277
+ );
278
+ destroyIsolate ();
279
+ } else {
280
+ _logger.fine (
281
+ 'Still have $actualClientCount clients available, keeping isolate alive' ,
282
+ );
283
+ // Update our internal counter to match reality
284
+ _activeConnectionCount = actualClientCount;
285
+ }
266
286
} else {
267
287
_logger.fine (
268
288
'Still have $_activeConnectionCount active connections, keeping isolate alive' ,
You can’t perform that action at this time.
0 commit comments