# Can't reopen socket (EADDRINUSE)

**URL:** <https://discourse.julialang.org/t/cant-reopen-socket-eaddrinuse/129345>\
**Category:** General Usage\
**Tags:** networking, sockets\
**Created:** [May 26, 2025, 12:31pm UTC](https://discourse.julialang.org/t/cant-reopen-socket-eaddrinuse/129345 "2025-05-26T12:31:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [May 26, 2025, 12:31pm UTC](https://discourse.julialang.org/t/cant-reopen-socket-eaddrinuse/129345/1 "2025-05-26T12:31:05Z")

</div>

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:

```julia
│ 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.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [May 26, 2025, 2:06pm UTC](https://discourse.julialang.org/t/cant-reopen-socket-eaddrinuse/129345/2 "2025-05-26T14:06:34Z")

</div>

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