Skip to content

Conversation

@tobil4sk
Copy link
Member

@tobil4sk tobil4sk commented Mar 20, 2025

If the socket doesn't belong to us, it is not safe to close it.

For example, on android which enables fdsan (file descriptor sanitizer), this can cause a hard crash if the socket comes from another thread EDIT: the actual cause for the crash was a double close.

It was a bit awkward to add a test for this because there is no easy way to check whether a socket is closed, and targets have slightly different behaviours, but hopefully this should do the job.

If we create the socket, we should also close it ourselves.
If the socket doesn't belong to us, it is not safe to close it.

For example, on android which enables fdsan (file descriptor sanitizer),
this can cause a hard crash if the socket comes from another thread.
@tobil4sk tobil4sk force-pushed the fix/http-dont-close-unowned-socket branch from 09c1310 to 33d0ec0 Compare March 20, 2025 22:38
@tobil4sk
Copy link
Member Author

Hm, actually, I'm not sure anymore if this fix makes sense... I think this may actually be something that should be addressed at the hxcpp level without changing the haxe api. I'll close for now and reopen if I find otherwise.

@tobil4sk tobil4sk closed this Mar 20, 2025
@tobil4sk
Copy link
Member Author

Ok, the actual culprit for the crash was hxcpp which didn't prevent you from closing a socket handle twice, so you were able to close a handle that didn't belong to you. This still seems like it could be a sensible change, however, if it makes more sense then I'd also be happy if we add documentation to customRequest that states it automatically closes the socket for you.

@tobil4sk tobil4sk reopened this Mar 21, 2025
@Simn
Copy link
Member

Simn commented Apr 6, 2025

I think this function cleaning up its own resources makes sense, so I'm happy to merge this.

@Simn Simn merged commit cbbb319 into HaxeFoundation:development Apr 6, 2025
117 of 118 checks passed
@tobil4sk tobil4sk deleted the fix/http-dont-close-unowned-socket branch April 6, 2025 09:11
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.

2 participants