[Boost-users] Boost/Asio short read error

906 views
Skip to first unread message

Marcin Głogowski

unread,
May 14, 2012, 9:22:20 AM5/14/12
to Boost...@lists.boost.org

Hi,

I have problem with Boost/asio – sometimes server returns „short read” error.

I’m using client/server from the examples.

Please write me – is it a bug or just wrong implemented example because the error occurs not every time.

How to protect my application against the error?

Best regards,

Marcin Głogowski

Dom Maklerski Banku Ochrony Środowiska Spółka Akcyjna
ul. Marszałkowska 78/80 / 00-517 Warszawa

wpisana w Rejestrze Przedsiębiorców prowadzonym przez
Sąd Rejonowy dla m. st. Warszawy XII Wydział Gospodarczy Krajowego Rejestru Sądowego
pod numerem: KRS 0000048901 / NIP 526-10-26-828

Kapitał zakładowy w wysokości 21.551.200zł wpłacony w całości.

P - Nie drukuj tej wiadomości, jeśli to nie jest konieczne.

Igor R

unread,
May 15, 2012, 6:11:23 AM5/15/12
to boost...@lists.boost.org
> I have problem with Boost/asio – sometimes server returns „short read”
> error.
> I’m using client/server from the examples.
> Please write me – is it a bug or just wrong implemented example because the
> error occurs not every time.
> How to protect my application against the error?

What boost/asio version do you use? What's your platform? What
specific example are you talking about?
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Marcin Głogowski

unread,
May 21, 2012, 4:43:34 AM5/21/12
to Boost...@lists.boost.org

Windows 7 64 bit ultimate, boost 1.49, examples from:

http://www.stderr.org/doc/libasio-doc/examples/ssl_client_cpp.html

http://www.stderr.org/doc/libasio-doc/examples/ssl_server_cpp.html

 

Currently SSL works great, but several days ago I had many times “short read” error.

Best regards

Marcin



> What boost/asio version do you use? What's your platform? What 
> specific example are you talking about? 

 

>> I have problem with Boost/asio – sometimes server returns „short read” 
>> error. 
>> I’m using client/server from the examples. 
>> Please write me – is it a bug or just wrong implemented example because the 
>> error occurs not every time. 
>> How to protect my application against the error? 

 

Dom Maklerski Banku Ochrony Środowiska Spółka Akcyjna

ul. Marszałkowska 78/80 / 00-517 Warszawa

Igor R

unread,
May 22, 2012, 4:38:21 AM5/22/12
to boost...@lists.boost.org
> Windows 7 64 bit ultimate, boost 1.49, examples from:
>
> http://www.stderr.org/doc/libasio-doc/examples/ssl_client_cpp.html
>
> http://www.stderr.org/doc/libasio-doc/examples/ssl_server_cpp.html
>
>
>
> Currently SSL works great, but several days ago I had many times “short
> read” error.


Ok, I see.
On "short read" you should re-start your async.operation (I believe
then you'll get eof).

Marcin Głogowski

unread,
May 22, 2012, 4:45:58 AM5/22/12
to boost...@lists.boost.org
Hi, thank you for help.
In the Asio mailing group another man wrote:
"Actually, it is not something to worry about.

Normally this error code is returned when the SSL client does not close its connection properly, i.e. without calling SSL_shutdown() (terminated from the task manager, for example).

The connection is closed by the client one way or another, the server can do nothing but ignore it.

You can check this error code as follows:
if (error.category() == boost::asio::error::get_ssl_category() &&
error.value() != ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)) // boost returns "short_read" wehen the peer calls SSL_shutdown() {
// the client went down abruptly
}"

What is the best way to handle the error - restart async operation or do checking as mentioned above?
Best regards
Marcin
Dom Maklerski Banku Ochrony Środowiska Spółka Akcyjna
ul. Marszałkowska 78/80 / 00-517 Warszawa

wpisana w Rejestrze Przedsiębiorców prowadzonym przez
Sąd Rejonowy dla m. st. Warszawy XII Wydział Gospodarczy Krajowego Rejestru Sądowego
pod numerem: KRS 0000048901 / NIP 526-10-26-828

Kapitał zakładowy w wysokości 21.551.200zł wpłacony w całości.

P - Nie drukuj tej wiadomości, jeśli to nie jest konieczne.

Igor R

unread,
May 22, 2012, 9:43:28 AM5/22/12
to boost...@lists.boost.org
> In the Asio mailing group another man wrote:
> "Actually, it is not something to worry about.
>
> Normally this error code is returned when the SSL client does not close its connection properly, i.e. without calling SSL_shutdown() (terminated from the task manager, for example).
>
> The connection is closed by the client one way or another, the server can do nothing but ignore it.
>
> You can check this error code as follows:
> if (error.category() == boost::asio::error::get_ssl_category() &&
>                        error.value() != ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)) // boost returns "short_read" wehen the peer calls SSL_shutdown() {
>   // the client went down abruptly
> }"
>
> What is the best way to handle the error - restart async operation or do checking as mentioned above?


Actually, after taking a look at the asio sources, I'm a bit confused:

const boost::system::error_code&
engine::map_error_code(boost::system::error_code& ec) const
{
// We only want to map the error::eof code.
if (ec != boost::asio::error::eof)
return ec;

// If there's data yet to be read, it's an error.
if (BIO_wpending(ext_bio_))
{
ec = boost::system::error_code(
ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
boost::asio::error::get_ssl_category());
return ec;
}

// SSL v2 doesn't provide a protocol-level shutdown, so an eof on the
// underlying transport is passed through.
if (ssl_ && ssl_->version == SSL2_VERSION)
return ec;

// Otherwise, the peer should have negotiated a proper shutdown.
if ((::SSL_get_shutdown(ssl_) & SSL_RECEIVED_SHUTDOWN) == 0)
{
ec = boost::system::error_code(
ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
boost::asio::error::get_ssl_category());
}

return ec;
}


So, in the both cases you get the same error_code (short read). If
"the peer negotiated a proper shutdown", and you try to read more,
wouldn't you get another "short read" - that's the question... I
believe you should experiment and see what you get.

Reply all
Reply to author
Forward
0 new messages