Skip to content

Socket is closed prematurely by the finalizer #397

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.

Activity

  1. takano-akio commented on Apr 19, 2019

    @takano-akio
    ContributorAuthor

    Oops, this is a duplicate of #396. Sorry about the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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