Search code examples
tcpwebsocketasioboost-beast

boost beast websocket server read with error code End of file and Operation cancelled


I am trying to setup a websocket server as described in this boost beast example.

Everything works fine except that the websocket stream read throw unexpeced system error with error code of "End of file" and "Operation cancelled"

beast::flat_buffer buffer;
try {
    ws->read(buffer); // ws is in the free store
}
catch(beast::system_error const& se) {
    if(se.code() == websocket::error::closed) {
        LOG_INFO << "ws closed, exiting handing thread..";
        break;
     }
    LOG_WARNING << "exception: " << se.code() << ", " << se.code().message();
}

After client connected to this server, and the server start to read incoming msg from the client with

ws->read(buffer);

From time to time, one End of file system_error and many operation cancelled system error are caught and printed as below:

WARNING  exception: asio.misc:2, End of file
WARNING  exception: system:125, Operation canceled
WARNING  exception: system:125, Operation canceled
WARNING  exception: system:125, Operation canceled

I googled around, End of file is probably caused by underlying tcp socket is closed, but the issue is that the disconnct happens very often and that does not make sense. And what exactly will cause Operation cancelled system error?


Solution

  • It turns out to be caused by bad netowrk. When I disable some VPN, the issue is gone.