Can't reopen socket (EADDRINUSE)

I’m writing a script where I open some TCP sockets to communicate with an external process. Once that process is finished I close the sockets and then I want to do the same thing again. When I try to open the sockets the second time I get this error:

│   exception =
│    IOError: listen: address already in use (EADDRINUSE)
│    Stacktrace:
│      [1] uv_error
│        @ ./libuv.jl:106 [inlined]
│      [2] #listen#13
│        @ ~/src/julia-1.11.5/share/julia/stdlib/v1.11/Sockets/src/Sockets.jl:632 [inlined]

I tried to make a minimum reproducible bug, but if I open and close the socket, it does work. I am closing the sockets as far as I can tell, I’m even priting the outptu of “isopen” after I close, and they seem to be getting closed. What could be going on here? Note that the sockets get used inside separate tasks.

Is it a race condition? Can you show more of the code?