Skip to content

Sockets can be closed prematurely on threaded #396

Description

@fumieval

7916e72 introduced a finaliser for a socket, but this may close the socket prematurely, resulting in Bad file descriptor error.

Reproducing example: tsurucapital@7496faa

Activity

  1. changed the title [-]Sockets can be closed prematurely[/-] [+]Sockets can be closed prematurely on threaded[/+] on Apr 19, 2019
  2. takano-akio commented on Apr 19, 2019

    @takano-akio
    Contributor

    See also #397.

  3. fumieval commented on Apr 19, 2019

    @fumieval
    ContributorAuthor

    A possible path would be

    1. remove the call to mkWeakIORef
    2. Merge Add withFdSocket #352
    3. Deprecate fdSocket
    4. Rewrite every use of fdSocket with withFdSocket
    5. Put mkWeakIORef back
    6. Remove fdSocket
  4. kazu-yamamoto commented on Apr 19, 2019

    @kazu-yamamoto
    Collaborator

    In private communication with @fumieval, I understand that this is due to GC.

    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 ()

    In this no loop example, sock is to be GCed while accept is blocked.

  5. kazu-yamamoto commented on Apr 19, 2019

    @kazu-yamamoto
    Collaborator

    fdSocket is not the main cause of this problem. But the place where fdSocket is used, this problem tends to appear. This proposal is to replace it with a safer API.

  6. kazu-yamamoto commented on Apr 24, 2019

    @kazu-yamamoto
    Collaborator

    #399 fixes this.

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

Metadata

Metadata

Assignees

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