TCP/IP Close Wait State

Though the process has terminated, its socket connection remains in TCP/IP,
which is noticeable in netstat -a which shows the connection state in Close
Wait. Due to this “unclosed” connection, the process cannot be restarted
because it cannot reuse the address. I have two choices, which is either to
wait until TCP/IP timeout and close the connection (which takes about 30
minutes), or slay Socket process.

Can anyone tell me how the connection gets into the Close Wait state? And is
there any command to Socket to clear the Close Wait connection?

“Johannes” <jsukamtoh@yahoo.com> wrote in message
news:9tgjpo$nrt$1@inn.qnx.com

Though the process has terminated, its socket connection remains in
TCP/IP,
which is noticeable in netstat -a which shows the connection state in
Close
Wait. Due to this “unclosed” connection, the process cannot be restarted
because it cannot reuse the address. I have two choices, which is either
to
wait until TCP/IP timeout and close the connection (which takes about 30
minutes), or slay Socket process.

This is a very frequent question in TCP/IP programming across the board.
You need to use the setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sockopt,
sockopt_len) call so that you can rebind to the port.

-Adam

“Operating System Tech Support” <os@qnx.com> wrote in message
news:9tglol$m5a$1@nntp.qnx.com

“Johannes” <> jsukamtoh@yahoo.com> > wrote in message
news:9tgjpo$nrt$> 1@inn.qnx.com> …
Though the process has terminated, its socket connection remains in
TCP/IP,
which is noticeable in netstat -a which shows the connection state in
Close
Wait. Due to this “unclosed” connection, the process cannot be restarted
because it cannot reuse the address. I have two choices, which is either
to
wait until TCP/IP timeout and close the connection (which takes about 30
minutes), or slay Socket process.

This is a very frequent question in TCP/IP programming across the board.
You need to use the setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &sockopt,
sockopt_len) call so that you can rebind to the port.

this is a standard solluion noted at “Advansed Sockets Programming” chapter
of tcp/tk documentation :slight_smile: it works for sure but as a part of the problem
i’v saw quite strange tcpip stack’s behaviour: even when socket no more
exists i.e. was closed by calling process, depending on remote peer socket
state connection record obtained with “netstat -a” still pending in
CLOSE_WAIT state. it’s ok, but sometimes when remote peer also closes its
socket it still exists and this time forever i.e. can be cleaned up only
after Tcpip stack restart. now imagine some situation, when clients are
connecting/disconnecting for example several times per minute this strange
way and what happens with stack itself after several hours of alike
operating.

i saw it with Tcpip v5.0X and [not sure] latest Socket 4.25. afair source
code with help of which i saw this stack overflow is avaialbe.

-Adam

// wbr