Skip to content

Commit

Permalink
Ensure port in listenany stays UInt16 (JuliaLang#47213)
Browse files Browse the repository at this point in the history
As reported [here](https://discourse.julialang.org/t/test-failures-for-sockets-base-runtests-sockets/88898).

My guess on the original issue reported is that, for some reason, the host where the tests are run
is unable to listen on any ports, so we end up cycling through the entire UInt16 range (the test
starts at port 11011), but when we fail on port 65535, we do `addr.port + 1` and instead of wrapping
around as I believe this function intends to happen (as noted by the `addr.port == default_port` check
before we error), it gets promoted to `Int(65536)` which then throws an (unexpected) error in the `InetAddr`
constructor.

I'm not quite sure how to test this exactly though, because we'd need to simulate not being able
to listen on any ports? If anyone has any ideas, I'm all ears.
  • Loading branch information
quinnj authored Oct 20, 2022
1 parent 0d52506 commit a311f4d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/Sockets/src/Sockets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ function listenany(host::IPAddr, default_port; backlog::Integer=BACKLOG_DEFAULT)
return (addr.port, sock)
end
close(sock)
addr = InetAddr(addr.host, addr.port + 1)
addr = InetAddr(addr.host, addr.port + UInt16(1))
if addr.port == default_port
error("no ports available")
end
Expand Down

0 comments on commit a311f4d

Please sign in to comment.