Skip to content

fix: close the inspector client socket on disconnect#390

Open
adrian-niculescu wants to merge 1 commit into
NativeScript:mainfrom
adrian-niculescu:fix/inspector-socket-leak-on-disconnect
Open

fix: close the inspector client socket on disconnect#390
adrian-niculescu wants to merge 1 commit into
NativeScript:mainfrom
adrian-niculescu:fix/inspector-socket-leak-on-disconnect

Conversation

@adrian-niculescu

@adrian-niculescu adrian-niculescu commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

The inspector's TCP server leaks a socket on every client disconnect.

When the debugger client closes the connection, the header read handler fires with an empty buffer and just returns:

const void* bytes = [(NSData*)data bytes];
if (!bytes) {
  return;
}

The dispatch_io channel is never closed there, so its cleanup handler never runs and the close(clientSocket) inside it never happens. Each connect/disconnect leaks one fd and one channel, which adds up across a debugging session with reconnects. Closing the channel on EOF lets the existing cleanup run.

I also relabeled the NSLog(@"Error: %s", ...) lines. Right now accept, header read, body read, send, and channel cleanup all log the same generic string, so you can't tell which stage actually failed.

Summary by CodeRabbit

  • Chores
    • Improved and standardized diagnostic error messages in the inspector server component. Messages are now more specific across connection handling, message header/body processing, connection acceptance, and message sending failures to aid troubleshooting without changing behavior or public APIs.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 863c6d3b-e84b-4f5d-8e39-0a64af022a68

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf3a6a and 2a80d8a.

📒 Files selected for processing (1)
  • NativeScript/inspector/InspectorServer.mm
✅ Files skipped from review due to trivial changes (1)
  • NativeScript/inspector/InspectorServer.mm

📝 Walkthrough

Walkthrough

Updated diagnostic NSLog messages in InspectorServer.mm to use consistent InspectorServer-prefixed error text at five failure points: channel cleanup, read message header, read message body, socket accept, and write Send. No control flow or public APIs changed.

Changes

Diagnostic Message Improvements

Layer / File(s) Summary
InspectorServer error message refinements
NativeScript/inspector/InspectorServer.mm
Five NSLog error messages are updated with InspectorServer-prefixed, context-specific text: channel cleanup error, read message header error, read message body error, accept() failure, and Send() write error.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hops through error logs so keen,
Adding names where failures might be seen,
"InspectorServer" now prefixed just right,
Debugging messages shining bright! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title claims to fix socket closure on disconnect, but the actual changes only update diagnostic log messages with no functional changes to socket handling. Update the title to reflect the actual changes: 'refactor: improve inspector error messages with stage-specific diagnostics' or include socket closure changes in the code.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
NativeScript/inspector/InspectorServer.mm (2)

106-106: 💤 Low value

Minor formatting inconsistency in accept() error message.

Line 106 contains NSLog(@"InspectorServer accept() failed;\n");. The embedded semicolon before the escape sequence is atypical (NSLog auto-appends newlines). Consider simplifying to:

NSLog(@"InspectorServer accept() failed");

This is a minor point and may be pre-existing; clarify intent if intentional.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@NativeScript/inspector/InspectorServer.mm` at line 106, In the
InspectorServer accept() error path, remove the extraneous semicolon and
explicit newline from the NSLog call: replace the current
NSLog(@"InspectorServer accept() failed;\n"); with a simpler
NSLog(@"InspectorServer accept() failed"); so the message is formatted
consistently (NSLog already appends a newline).

147-147: 💤 Low value

Send() error message uses inconsistent naming convention.

Line 147 uses "InspectorServer::Send error" (with :: C++ scope operator), while other messages use space-separated context. For consistency with lines 50, 59, 77, consider:

NSLog(@"InspectorServer Send error: %s", strerror(error));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@NativeScript/inspector/InspectorServer.mm` at line 147, The log message in
InspectorServer::Send currently uses an inconsistent C++ scope operator
("InspectorServer::Send error"); change the NSLog format string to match the
project's space-separated convention (e.g., "InspectorServer Send error: %s") so
it is consistent with other messages (see InspectorServer::Send and other NSLog
calls around lines 50, 59, 77).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@NativeScript/inspector/InspectorServer.mm`:
- Line 106: In the InspectorServer accept() error path, remove the extraneous
semicolon and explicit newline from the NSLog call: replace the current
NSLog(@"InspectorServer accept() failed;\n"); with a simpler
NSLog(@"InspectorServer accept() failed"); so the message is formatted
consistently (NSLog already appends a newline).
- Line 147: The log message in InspectorServer::Send currently uses an
inconsistent C++ scope operator ("InspectorServer::Send error"); change the
NSLog format string to match the project's space-separated convention (e.g.,
"InspectorServer Send error: %s") so it is consistent with other messages (see
InspectorServer::Send and other NSLog calls around lines 50, 59, 77).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e99ec547-5a18-439f-8118-8d5dd0d38169

📥 Commits

Reviewing files that changed from the base of the PR and between 05224d3 and 9cf3a6a.

📒 Files selected for processing (1)
  • NativeScript/inspector/InspectorServer.mm

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.
@adrian-niculescu adrian-niculescu force-pushed the fix/inspector-socket-leak-on-disconnect branch from 9cf3a6a to 2a80d8a Compare June 13, 2026 20:32
@adrian-niculescu

Copy link
Copy Markdown
Contributor Author

🧹 Nitpick comments (2)

NativeScript/inspector/InspectorServer.mm (2)> 106-106: 💤 Low value

Minor formatting inconsistency in accept() error message.
Line 106 contains NSLog(@"InspectorServer accept() failed;\n");. The embedded semicolon before the escape sequence is atypical (NSLog auto-appends newlines). Consider simplifying to:

NSLog(@"InspectorServer accept() failed");

This is a minor point and may be pre-existing; clarify intent if intentional.

🤖 Prompt for AI Agents

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@NativeScript/inspector/InspectorServer.mm` at line 106, In the
InspectorServer accept() error path, remove the extraneous semicolon and
explicit newline from the NSLog call: replace the current
NSLog(@"InspectorServer accept() failed;\n"); with a simpler
NSLog(@"InspectorServer accept() failed"); so the message is formatted
consistently (NSLog already appends a newline).

147-147: 💤 Low value
Send() error message uses inconsistent naming convention.
Line 147 uses "InspectorServer::Send error" (with :: C++ scope operator), while other messages use space-separated context. For consistency with lines 50, 59, 77, consider:

NSLog(@"InspectorServer Send error: %s", strerror(error));

🤖 Prompt for AI Agents

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@NativeScript/inspector/InspectorServer.mm` at line 147, The log message in
InspectorServer::Send currently uses an inconsistent C++ scope operator
("InspectorServer::Send error"); change the NSLog format string to match the
project's space-separated convention (e.g., "InspectorServer Send error: %s") so
it is consistent with other messages (see InspectorServer::Send and other NSLog
calls around lines 50, 59, 77).

🤖 Prompt for all review comments with AI agents

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@NativeScript/inspector/InspectorServer.mm`:
- Line 106: In the InspectorServer accept() error path, remove the extraneous
semicolon and explicit newline from the NSLog call: replace the current
NSLog(@"InspectorServer accept() failed;\n"); with a simpler
NSLog(@"InspectorServer accept() failed"); so the message is formatted
consistently (NSLog already appends a newline).
- Line 147: The log message in InspectorServer::Send currently uses an
inconsistent C++ scope operator ("InspectorServer::Send error"); change the
NSLog format string to match the project's space-separated convention (e.g.,
"InspectorServer Send error: %s") so it is consistent with other messages (see
InspectorServer::Send and other NSLog calls around lines 50, 59, 77).

ℹ️ Review info

Addressed the nitpick review comments, as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant