-
Notifications
You must be signed in to change notification settings - Fork 190
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
Add unsafeFdSocket and touchSocket (Fixes #418) #422
Conversation
There is nothing specific to fdSocket about this race condition.
I believe this is not correct. It's specific to |
It seems to me that the following sequence of events could happen.
I believe some kind of locking is necessary to prevent this race condition. |
@vdukhovni Akio pointed out a possible race condition for the current code. The |
The But I think this is too expensive, and generally unnecessary. What've implemented is safe finalization, which coexists with "prompt" resource deallocation via explicit I think that's enough. |
I agree with @vdukhovni. It's application's bug. |
In terms of documentation though, yes any use of |
-- | Ensure that the given 'Socket' stays alive (i.e. not garbage-collected) | ||
-- at the given place in the sequence of IO actions. This function can be | ||
-- used in conjunction with 'unsafeFdSocket' to guarantee that the file | ||
-- descriptor is not prematurely freed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs an example showing the function is used in a code block that keeps the socket alive...
Putting aside the question of locking, and supporting concurrent close, this PR makes it possible to use |
I would like to divide this issue to three items:
I will take care of (1) first. |
For (1), I would like to merge #423 instead of #422 (this one). |
Largely, yes, but I see that #423 has To the extent that you are already touching the documentation of (possibly new) functions, perhaps this is an opportunity to make the documentation a bit more detailed. I find that Haskell documentation (and generally documentation derived from comments in source code rather than written separately as with manpages) is often too terse, and examples are often not provided. It would be good to provide more detailed usage guidance. |
Good point! |
#423 has been merged. Let's close this. |
This branch implements
unsafeFdSocket
andtouchSocket
as discussed in #418.Before making the actual change, I had to update/move the warning about race condition in the doc for
fdSocket
because (if I understand correctly) it was very misleading. Basically the race condition is not specific tofdSocket
at all, and it applies to any combination ofclose
and a normal socket operation (likerecv
). Please review the doc update carefully because it's a tricky topic and I may well have made mistakes.