1

Reference: websocket_client_sync_ssl.cpp

// Read a message into our buffer
ws.read(buffer);

// Close the WebSocket connection
ws.close(websocket::close_code::normal);
    

Based on my test, the ws.close will spit out a warning below:

ERROR message: short read (SSL routines, SSL routines), value: 335544539

Based on this post short read, this error can be safely ignored in the end of the session. I have tried the following method to suppress the warning:

try
{
  boost::system::error_code close_ec;
  ws.close(websocket::close_code::normal, close_ec);
  if (close_ec)
  {
    std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;
  }
}
catch(...)
{

}
    

However, the ws.close still prints out the warning message.

Question> Is there a way that I can suppress this message?

1 Answer 1

1

However, the ws.close still prints out the warning message.

Are you sure? It looks like that's simply coming from the line:

std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;

So, you would check the value of close_ec and conditionally handle it: Short read error-Boost asio synchoronous https call

Also, note that some kinds of "short reads" can constitute security errors. Some of the samples have very insightful comments about this:

// `net::ssl::error::stream_truncated`, also known as an SSL "short read",
// indicates the peer closed the connection without performing the
// required closing handshake (for example, Google does this to
// improve performance). Generally this can be a security issue,
// but if your communication protocol is self-terminated (as
// it is with both HTTP and WebSocket) then you may simply
// ignore the lack of close_notify:
//
// https://github.com/boostorg/beast/issues/38
//
// https://security.stackexchange.com/questions/91435/how-to-handle-a-malicious-ssl-tls-shutdown
//
// When a short read would cut off the end of an HTTP message,
// Beast returns the error beast::http::error::partial_message.
// Therefore, if we see a short read here, it has occurred
// after the message has been completed, so it is safe to ignore it.

if(ec == net::ssl::error::stream_truncated)
    ec = {};
else if(ec)
    return;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.