From 2a80d8a2c05b22d555a2c492934bc17509857cb1 Mon Sep 17 00:00:00 2001 From: Adrian Niculescu <15037449+adrian-niculescu@users.noreply.github.com> Date: Sat, 13 Jun 2026 22:59:08 +0300 Subject: [PATCH] fix: close the inspector client socket on disconnect 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. --- NativeScript/inspector/InspectorServer.mm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/NativeScript/inspector/InspectorServer.mm b/NativeScript/inspector/InspectorServer.mm index 670bbe4b..c18b8758 100644 --- a/NativeScript/inspector/InspectorServer.mm +++ b/NativeScript/inspector/InspectorServer.mm @@ -47,7 +47,7 @@ dispatch_io_t channel = dispatch_io_create(DISPATCH_IO_STREAM, clientSocket, q, ^(int error) { if (error) { - NSLog(@"Error: %s", strerror(error)); + NSLog(@"InspectorServer channel cleanup error: %s", strerror(error)); } close(clientSocket); }); @@ -56,11 +56,12 @@ __block dispatch_io_handler_t receiver = ^(bool done, dispatch_data_t data, int error) { if (error) { - NSLog(@"Error: %s", strerror(error)); + NSLog(@"InspectorServer read message header error: %s", strerror(error)); } const void* bytes = [(NSData*)data bytes]; if (!bytes) { + dispatch_io_close(channel, DISPATCH_IO_STOP); return; } @@ -73,7 +74,7 @@ dispatch_io_read(channel, 0, length, q, ^(bool done, dispatch_data_t data, int error) { BOOL close = NO; if (error) { - NSLog(@"Error: %s", strerror(error)); + NSLog(@"InspectorServer read message body error: %s", strerror(error)); close = YES; } @@ -102,7 +103,7 @@ dispatch_io_read(channel, 0, 4, q, receiver); } } else { - NSLog(@"accept() failed;\n"); + NSLog(@"InspectorServer accept() failed"); } } }); @@ -143,7 +144,7 @@ dispatch_io_write(channel, 0, data, queue, ^(bool done, dispatch_data_t data, int error) { if (error) { - NSLog(@"Error: %s", strerror(error)); + NSLog(@"InspectorServer::Send error: %s", strerror(error)); } }); }