Skip to content

bindPortTCP: Confusing exception type when port is already in use #79

Open
@sol

Description

To reproduce:

{-# LANGUAGE OverloadedStrings #-}
import Control.Exception
import Network.Socket
import Data.Streaming.Network

main :: IO ()
main = do
  _ <- bindPortTCP 3000 "*"
  try @SomeException (bindPortTCP 3000 "*") >>= print
  try @SomeException (bindPortAny 3000) >>= print

bindPortAny :: PortNumber -> IO Socket
bindPortAny port = do
  sock <- socket AF_INET Stream defaultProtocol
  setSocketOption sock ReuseAddr 1
  bind sock (SockAddrInet port anyInterface)
  listen sock maxListenQueue
  return sock

anyInterface :: HostAddress
anyInterface = tupleToHostAddress (0, 0, 0, 0)
$ cabal install --lib --package-env=. base-4.20.0.0 network-3.2.1.0 streaming-commons-0.2.2.6
$ runhaskell streaming-commons-bug.hs

Actual:

Left Network.Socket.socket: unsupported operation (Address family not supported by protocol)
Left Network.Socket.bind: resource busy (Address already in use)

Expected:

Left Network.Socket.bind: resource busy (Address already in use)
Left Network.Socket.bind: resource busy (Address already in use)

Activity

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

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