Opened 6 years ago

#12528 new Bugs

boost::asio::ssl_stream "short read error" when a connection is closed

Reported by: Nakao_Kazuhiro@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.62.0 Severity: Problem
Keywords: Cc:

Description

I use boost::asio to make client/server programs using SSL and I use boost::asio example as a reference. The problem is that when client or server closes the connection, the other side has "short read error". Using NOT SSL, this problem isn't detected, this is the problem using SSL. When the client program closes connection, the server has "short read error". The other way, the server program closes connection, the client has "short read error" too. The original sample programs don't output errors, so I add the codes which output errors.

http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/example/cpp03/ssl/client.cpp

[server.cpp]

void handle_read(const boost::system::error_code& error, size_t bytes_transferred) {
    if (!error)
    {
      boost::asio::async_write(socket_,
          boost::asio::buffer(data_, bytes_transferred),
          boost::bind(&session::handle_write, this,
            boost::asio::placeholders::error));
    }
    else
    {
      std::cout << "Server Error: " << error.message() << "\n"; //add
      delete this;
    }
}

void handle_write(const boost::system::error_code& error) {
    if (!error)
    {
      socket_.async_read_some(boost::asio::buffer(data_, max_length),
          boost::bind(&session::handle_read, this,
            boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));
    }
    else
    {
      std::cout << "Server Error: " << error.message() << "\n"; //add
      delete this;
    }
}

The sample programs don't use "socket_.shutdown()" and "socket_.lowest_layer().close()". The shutting down process is automatically executed by the destructor. I use "socket_.shutdown()" and "socket_.lowest_layer().close()" using the following page as a reference, but the same error happens. http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error

Other hand, the release note of Boost_1.58.0 has the Updated Libraries log which is "Fixed an ssl::stream<> bug that may result in spurious 'short read' errors". I can't figure out this change has relations about this problem, but this event is already detected. http://www.boost.org/users/history/version_1_58_0.html

Change History (0)

Note: See TracTickets for help on using tickets.