[Haskell-cafe] addFinalizer in GHC 7.10
Kazu Yamamoto (=?iso-2022-jp?B?GyRCOzNLXE9CSScbKEI=?=)
kazu at iij.ad.jp
Tue Jan 30 05:18:56 UTC 2018
I registered this issue to network:
Viktor, thank you!
>> On Jan 29, 2018, at 10:25 PM, Kazu Yamamoto (山本和彦) <kazu at iij.ad.jp> wrote:
>> socket family stype protocol = do
>> fd <- c_socket ...
>> let s = Socket fd
>> addFinalizer s $ close s
>> ruturn s
> For the record, I think I've convinced Kazu Yamamoto that this is
> an anti-pattern. Such a finalizer would easily end up closing
> already closed sockets, whose file-descriptors may already be
> associated with other open files or sockets. That way lie all
> sorts of difficult to isolate race-condition bugs. To make this
> safe, the close function would need to mutate the socket,
> invalidating the enclosed file-descriptor, and would then need to
> be a NOP or just raise an exception if the socket is closed again
> (the finalizer should invoke a close variant that just returns
> without raising exceptions if the socket is already closed).
> There is, AFAIK still an unresolved bug along these lines somewhere
> in http-client and its dependencies. So far no reproducing cases have
> been provided. No very recent reports either, perhaps it went away,
> or people have just been more lucky lately:
> All that said, the original question about addFinalizer vs. GHC 7.10
> may still be worth exploring, even if its use-case for Sockets goes
> away. So, please don't take this poset to mean that the original
> question should be ignored.
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe