You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I took a quick look at fixing this, and it's not completely trivial.
The easiest thing, I thought, would be to use addMVarFinalizer to associate a finalizer with the MVar we already use to track the socket state. But the finalizer would want to know the state of the socket in order to close it safely, and if the finalizer has a reference to the MVar to read its state, I think that will unintentionally keep the MVar alive.
We cannot simply unconditionally c_close the file descriptor, because by the time the finalizer is called on a closed Socket, the fd will probably refer to a different file entirely.
So. Instead, I'm adding a finalizer to the 'Socket' itself, using 'System.Mem.Weak'.
I'm currently trying to get an overview of the state of the network package.
What is the state of this issue? I grepped the package for 'Weak' without result and therefore assume that whatever you did, did not make it into master.
For anyone stumbling upon this issue: The finalization mechanism proposed by @bos does work when using mkWeakMVar (instead of now obsolete addMVarFinalizer). The considerations with the finalizer itself keeping the MVar alive do not apply.
Yow! I just noticed this. If you create a
Socket, it stays open forever even if no longer reachable.