Skip to content

Socket is closed prematurely by the finalizer #397

@takano-akio

Description

@takano-akio

When compiled with -threaded, the following program crashes with the message: threadWait: invalid argument (Bad file descriptor). This happens with network-3.0.1.1 and with HEAD, but not with network-2.6.3.6.

import Network.Socket

main :: IO ()
main = do
  sock <- socket AF_INET Stream defaultProtocol
  setSocketOption sock ReuseAddr 1
  bind sock $ SockAddrInet 6000 $ tupleToHostAddress (127, 0, 0, 1)
  listen sock 1
  _ <- accept sock
  return ()

This seems to be caused by the fact that the accept function doesn't ensure that the internal IORef inside the socket remains referenced until the accept operation is complete. The solution would be to implement something like #352 and use it in every function that might block, like accept or recvBuf.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions