[Libwebsockets] lws client issues lws_close_reason but socket is not closed for 20 secs

Dave Horton daveh at beachdognet.com
Fri Jan 31 17:20:23 CET 2020


I have an lws client running against a non-lws websocket server.  I suspect what I am seeing is a problem in the server implementation, but I need some insight into how the client handles close.

I am calling lws_close_reason(wsi, LWS_CLOSE_STATUS_NORMAL, NULL, 0); in my lws callback and then return -1 from the callback.

I expect this to close the websocket immediately. (I know I’m probably wrong on this)

What I see happening is that the socket is closed on the server side exactly 20 secs later.

If I take a network trace, I do not see any tcp message from the client to the server at the point that I called lws_close_reason

Instead I see a PING message 20 seconds later, followed by a CLOSE frame.

My suspicion is that the lws client is possibly waiting for outstanding binary frames I have been sending to be ACK’ed, or something like that?

If I compare to a trace from a “good” working server (meaning it disconnects immediately upon lws_close_reason) I see the following differences

interaction with “bad” server:
———————————

client sends 2 BINARY frames (always 640 bytes each) with tcp flags ACK,PUSH and websocket flag FIN set
server sends ACK back, containing acknowledgement number of next-seq in the second BINARY frame
..this repeats until lws_close_reason is called at which point there is a 20 sec delay after last ACK is received from server until PING,CLOSE

interaction with “good” server
—————————————

client sends 1 BINARY frame (usually 1240 bytes or more, variable length) with ACK, PUSH and websocket flag FIN set
server sends ACK back, containing acknowledgement number of seq in BINARY frame above (note difference from above)
client sends TCP frame with ACK, PUSH set acknowledging above frame
server sends ACK backm containing acknowledgement number of TCP frame immediately above
…this repeats until lws_close_reason is called at which point CLOSE frame is immediately sent


Any insight into what is going on with the 20-sec delay?

Dave





More information about the Libwebsockets mailing list