Skip to content

bindPortTCP fails to report port in use on OSX #29

@simonmichael

Description

@simonmichael

On OSX, I can run two instances of my yesod app on the same port without error. The first "shadows" the second; the second starts receiving requests after the first terminates (simonmichael/hledger#226).

I can reproduce this with bindPortTCP:

#!/usr/bin/env stack
{- stack runghc --package network --package streaming-commons -}
{-# LANGUAGE OverloadedStrings #-}

import Data.Streaming.Network
import Network.Socket

main = do
  let port = 5001
      host = "*4"
      -- host = "!4"
  putStr "should pass: " >> bindPortTCP port host >>= print
  putStr "should fail: " >> bindPortTCP port host >>= print -- doesn't fail on OSX. With host = "!4" it does
  putStr "should fail: " >> bindPortTCP port host >>= print

On GNU/Linux, it fails when expected:

$ ./226-test.hs
should pass: <socket: 10>
should fail: 226-test.hs: bind: resource busy (Address already in use)

but on OSX, it doesn't fail until the third bind:

$ ./226-test.hs 
should pass: <socket: 22>
should fail: <socket: 23>
should fail: 226-test.hs: bind: resource busy (Address already in use)

(I don't know about Windows.)

If I change the host preference from "*4" to "!4", it works as expected.

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