Le 19/10/16 à 11:27, Michał Gałuszka a écrit :
> Dear MINA users.
>
> I’m using MINA server acceptor in my Java application that needs to be 
> restarted from time to time.
> When I stop and start that application „too fast” I always get an exception 
> when starting and trying to bind:
>
> java.io.IOException: Error while binding on 0.0.0.0/0.0.0.0:8245
> original message : Address already in use
>
> It must mean that I’m not closing all connections correctly upon application 
> termination.
> I have tried many things but nothing helped.
>
> When terminating application I’m closing all sessions (most often there is 
> only one session open), wait for the session to close gracefully and then I 
> fire 
>
> acceptor.dispose(true);
>
> I’m not calling acceptor.unbind() because it is already called inside 
> dispose(). Right?
>
> After few minutes I can always start my application and then
> acceptor.bind(new InetSocketAddress(port));
> will work correctly not throwing any Exception.
This is inherent to the way TCP works. You can have a look at
http://hea-www.harvard.edu/~fine/Tech/addrinuse.html.

You can try to setup the SO_REUSEADRESS flag to mitigate the problem,
using the setReuseAddress( true ) method on your service.

Reply via email to