SDK binds to TCP listening port without enabling SO_REUSEADDR

Document created by cdnadmin on Jan 24, 2014
Version 1Show Document
  • View in full screen mode
This document was generated from CDN thread

Created by: Christopher Verges on 21-07-2010 04:45:32 AM
When creating the TCP listener socket through energywise_svc_create() and using a static TCP port (38836 in the example below), restarting the EnergyWise agent will cause the port to be unusable for a certain amount of time after the first agent daemon stops running.
 
Example output using static listen port 38836 with TRACE debugging enabled:
...
Wed Jul 21 04:20:53 2010  energywise_svc_create: Converting 10.0.3.120 (len=10) to inet address
Wed Jul 21 04:20:53 2010  new_svc_session: allocated 744 bytes for svc session
Wed Jul 21 04:20:53 2010  energywise_svc_create: Write socket set to broadcast mode
Wed Jul 21 04:20:53 2010  energywise_svc_create: Write socket set to reuse address
Wed Jul 21 04:20:53 2010  energywise_svc_create: Bind to broadcast socket 10.0.3.120:37034
Wed Jul 21 04:20:53 2010  bindTcpListener: Bind failed server:0.0.0.0, port:38836(Address already in use:98)
Wed Jul 21 04:20:53 2010  energywise_svc_create: Failed to bind port
...
 
This problem is caused by the TCP socket being created without the use of the SO_REUSEADDR flag.  From http://www.unixguide.net/network/socketfaq/4.5.shtml:

This socket option tells the kernel that even if this port is busy (in
  the TIME_WAIT state), go ahead and reuse it anyway.  If it is busy,
  but with another state, you will still get an address already in use
  error.  It is useful if your server has been shut down, and then
  restarted right away while sockets are still active on its port.  You
  should be aware that if any unexpected data comes in, it may confuse
  your server, but while this is possible, it is not likely.
 
For daemons like the EnergyWise agent, this is crucial if a static listener port is to be used.

Subject: RE: SDK binds to TCP listening port without enabling SO_REUSEADDR
Replied by: Christopher Verges on 26-07-2010 11:08:11 PM
Fixed in toolkit released on 2010-07-22.  Thanks Brad!
 
Chris

Attachments

    Outcomes