Skip to content

Fix ICMP socket leak in hs.ping - #3419

Merged
cmsj merged 1 commit into
masterfrom
fix-ping-sockets-not-closing
Mar 11, 2023
Merged

cmsj merged 1 commit into
masterfrom
fix-ping-sockets-not-closing

Conversation

@cmsj

@cmsj cmsj commented Mar 10, 2023

Copy link
Copy Markdown
Member

No description provided.

@cmsj cmsj added this to the 0.9.98 milestone Mar 10, 2023
@cmsj cmsj added the pr-fix Pull Request implementing a bug fix label Mar 10, 2023
@cmsj cmsj self-assigned this Mar 10, 2023
@cmsj
cmsj requested a review from asmagill March 10, 2023 00:53
@github-actions

Copy link
Copy Markdown

View Test Results

348 tests   296 ✔️  11m 44s ⏱️
    2 suites    52 💤
    1 files        0 ❌

Results for commit f30c5c0.

@asmagill

Copy link
Copy Markdown
Member

I'll try and take a look at it tomorrow (later today I guess at this point...)

@cmsj

cmsj commented Mar 10, 2023

Copy link
Copy Markdown
Member Author

@asmagill thanks! There's a bit of commentary in the related bug, but the tl;dr is that kCFSocketCloseOnInvalidate, while set by default (and assert()ed as present) when the socket is created, is later unset in - (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address so the underlying native socket is never closed.

At least that is true for the simple case of calling hs.network.ping() in a one-shot style. I'm wondering if there's something I've missed for more complex cases, but even so I think this patch should be safe in any case, because it's in the path of CFSocketInvalidate() so there should be no reason for the underlying native socket to exist beyond that point.

@asmagill

Copy link
Copy Markdown
Member

Yeah, your logic tracks and the code looks good.

I'm a little curious as to why the flag is removed in the simplePing method -- I'll try and dig into the actual SimplePing code this weekend and see if I can figure out why and if we're still open to issues in more complex use cases, but from reading the CFSocket stuff in Apple's docs, I agree that this added check is needed.

@cmsj

cmsj commented Mar 11, 2023

Copy link
Copy Markdown
Member Author

Thanks!

@cmsj
cmsj merged commit 3ca0cb9 into master Mar 11, 2023
@cmsj
cmsj deleted the fix-ping-sockets-not-closing branch March 11, 2023 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull Request implementing a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants