dhbaird / easywsclient

A short and sweet WebSocket client for C++
MIT License
753 stars 204 forks source link

Websocket::close() doesn't disconnect correctly #71

Open Henrik0x7F opened 6 years ago

Henrik0x7F commented 6 years ago

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

aniongithub commented 6 years ago

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

Henrik0x7F commented 6 years ago

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.

hosseinpro commented 4 years ago

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.

james-richey-gv commented 3 years ago

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.