Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sol opened this issue Aug 3, 2024 · 0 comments
Open

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

sol opened this issue Aug 3, 2024 · 0 comments

Comments

@sol
Copy link

sol commented Aug 3, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant