mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.83k stars 1.66k forks source link

[BUG] 'Address already in use' when restart after SocketIOClient.disconnect() and SocketIOServer.stop() #996

Open yuan-java opened 3 months ago

yuan-java commented 3 months ago
  1. start server and a client
  2. socket IO connected
  3. call SocketIOClient.disconnect() and SocketIOServer.stop(), then close server
  4. start server again, then get the following issue:

Exception in thread "main" io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use

  1. wait for around 1 minute, restart again successfully

The issue happens from 1.x to latest 2.0.11.

Thanks

birkoni5 commented 3 months ago

Does the solution from the issue help?

REUSE_PORT solves your problem, try this code when you start server

  val config = Configuration()
  config.setPort(port)
  val sockConfig = SocketConfig()
  sockConfig.setReuseAddress(true)
  config.setSocketConfig(sockConfig)
  val server = SocketIOServer(config)
yuan-java commented 3 months ago

it works, thank you!