Skip to content

Commit e271a77

Browse files
fix: close the inspector client socket on disconnect (#390)
When the debugger client closes the connection, the header read handler fires with an empty buffer and returns without closing the dispatch_io channel, so the channel cleanup never runs and close(clientSocket) is never called. Each connect/disconnect leaks one fd and one channel. Close the channel on EOF so the existing cleanup runs, and label the NSLog messages so it's clear which stage failed.
1 parent 05224d3 commit e271a77

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

NativeScript/inspector/InspectorServer.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
dispatch_io_t channel =
4848
dispatch_io_create(DISPATCH_IO_STREAM, clientSocket, q, ^(int error) {
4949
if (error) {
50-
NSLog(@"Error: %s", strerror(error));
50+
NSLog(@"InspectorServer channel cleanup error: %s", strerror(error));
5151
}
5252
close(clientSocket);
5353
});
@@ -56,11 +56,12 @@
5656

5757
__block dispatch_io_handler_t receiver = ^(bool done, dispatch_data_t data, int error) {
5858
if (error) {
59-
NSLog(@"Error: %s", strerror(error));
59+
NSLog(@"InspectorServer read message header error: %s", strerror(error));
6060
}
6161

6262
const void* bytes = [(NSData*)data bytes];
6363
if (!bytes) {
64+
dispatch_io_close(channel, DISPATCH_IO_STOP);
6465
return;
6566
}
6667

@@ -73,7 +74,7 @@
7374
dispatch_io_read(channel, 0, length, q, ^(bool done, dispatch_data_t data, int error) {
7475
BOOL close = NO;
7576
if (error) {
76-
NSLog(@"Error: %s", strerror(error));
77+
NSLog(@"InspectorServer read message body error: %s", strerror(error));
7778
close = YES;
7879
}
7980

@@ -102,7 +103,7 @@
102103
dispatch_io_read(channel, 0, 4, q, receiver);
103104
}
104105
} else {
105-
NSLog(@"accept() failed;\n");
106+
NSLog(@"InspectorServer accept() failed");
106107
}
107108
}
108109
});
@@ -143,7 +144,7 @@
143144

144145
dispatch_io_write(channel, 0, data, queue, ^(bool done, dispatch_data_t data, int error) {
145146
if (error) {
146-
NSLog(@"Error: %s", strerror(error));
147+
NSLog(@"InspectorServer::Send error: %s", strerror(error));
147148
}
148149
});
149150
}

0 commit comments

Comments
 (0)