easywsclient icon indicating copy to clipboard operation
easywsclient copied to clipboard

Websocket::close() doesn't disconnect correctly

Open Henrik0x7F opened this issue 6 years ago • 4 comments

I'm calling Websocket::close() in my destructor, but the it disconnects only if I close my program.

Henrik0x7F avatar Jan 13 '18 10:01 Henrik0x7F

Any progress on this? I'm facing the same problem.

aniongithub avatar Oct 24 '18 02:10 aniongithub

My workaround was to add closesocket(sockfd); after line 425 in easywsclient.cpp. I don't know if it closes the connection properly but it at least doesn't keep it open forever. I myself have switched to websocketpp, a more complete library which doesn't suffer from this issue.

Henrik0x7F avatar Oct 27 '18 15:10 Henrik0x7F

My workaround was to add closesocket(sockfd); after line 425 in easywsclient.cpp. I don't know if it closes the connection properly but it at least doesn't keep it open forever. I myself have switched to websocketpp, a more complete library which doesn't suffer from this issue.

it works. not exact line 425, but at the end of close() function body.

hosseinpro avatar Jul 24 '20 14:07 hosseinpro

I have noticed this behavior can be seen by running the tests:

  1. Build the tests with make test, start the testServer.js with node, and launch easywsclient.t in a debugger such as GDB.
  2. Place a breakpoint at the end of main() to prevent the test application from closing after RUN_ALL_TESTS() returns.
  3. Run the the tests.
  4. Once the breakpoint is hit, note there are several open TCP sockets. For example, on Linux:
    $ lsof -p $(pidof easywsclient.t) | grep TCP
    easywscli 22634 james    3u  IPv6 634795      0t0     TCP localhost:36496->localhost:8123 (ESTABLISHED)
    easywscli 22634 james    4u  IPv6 634799      0t0     TCP localhost:36498->localhost:8123 (ESTABLISHED)
    easywscli 22634 james    5u  IPv6 643270      0t0     TCP localhost:36500->localhost:8123 (ESTABLISHED)
    easywscli 22634 james    6u  IPv6 643274      0t0     TCP localhost:36502->localhost:8123 (ESTABLISHED)
    

I expected the TCP sockets to be closed when the WebSocket class is destroyed, regardless if WebSocket::close() has been called. I observed this behavior with commit afc1d8cfc584e0f1f4a77e8c0ce3e979d9fe7ce2.

james-richey-gv avatar Jun 14 '21 23:06 james-richey-gv