Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICMP socket leak in hs.ping #3419

Merged
merged 1 commit into from Mar 11, 2023
Merged

Fix ICMP socket leak in hs.ping #3419

merged 1 commit into from Mar 11, 2023

Conversation

cmsj
Copy link
Member

@cmsj cmsj commented Mar 10, 2023

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
@github-actions
Copy link

View Test Results

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

Results for commit f30c5c0.

@asmagill
Copy link
Member

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

@cmsj
Copy link
Member Author

cmsj commented Mar 10, 2023

@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
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
Copy link
Member Author

cmsj commented Mar 11, 2023

Thanks!

@cmsj cmsj merged commit 3ca0cb9 into master Mar 11, 2023
4 checks passed
@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.

None yet

2 participants