[asio] SSL operation sporadically returns "Access is denied"

I recently grabbed the latest ASIO out of the boost CVS in hopes of fixing some SSL problems we were having in an example program I posted a while back. The changes did indeed fix the problem I outlined in the example program (thanks Chris!). However, I'm still getting random lockups when I enable SSL. The problems may very well stem from our code, but I've spent so much wasted time trying to track it down I'm hoping someone might be able to shed some light on why this happens. I'm running on Windows XP Professional and compiling with MSVS 2003. In almost all cases, our client will eventually get an asio::error returned from the following call: // _inboundHeader is an unsigned char array declared as member data of // the Connection class and does get destroyed before the read is // completed asio::async_read(*_sslSocket, asio::buffer(_inboundHeader, sizeof _inboundHeader), boost::bind(&Connection::handleReadResHeader, this, _1, _2, handler)); The asio::error object says "Access is denied". I've tracked the error to ssl/detail/openssl_operation.hpp, line 171. Snippet follows: if (!is_operation_done && !is_read_needed && !is_write_needed && !is_shut_down_sent) // The operation has failed... It is not completed and does // not want network communication nor does want to send shutdown out... return handler_(boost::asio::error(error_code), rc); error_code = 5 and rc = -1 Can anyone shed some light on what causes such a failure? Like I said, this has been driving me batty for some time now. Any help would be greatly, greatly appreciated! :) Scott

Hi Scott, Scott <cheesy4poofs@cox.net> wrote:
However, I'm still getting random lockups when I enable SSL. The problems may very well stem from our code, but I've spent so much wasted time trying to track it down I'm hoping someone might be able to shed some light on why this happens. [...] The asio::error object says "Access is denied".
The error is actually SSL_ERROR_SYSCALL (which is 5), and it's showing up as "access denied" because it's not getting mapped correctly. Can you try the changes to openssl_operation.hpp shown below and see what you get as the real error. Thanks. Cheers, Chris --------------------------------- @@ -25,6 +25,7 @@ #include "asio/buffer.hpp" #include "asio/placeholders.hpp" #include "asio/write.hpp" +#include "asio/detail/socket_ops.hpp" #include "asio/ssl/detail/openssl_types.hpp" namespace asio { @@ -141,6 +142,7 @@ int error_code = !is_operation_done ? ::SSL_get_error( session_, rc ) : 0; + int sys_error_code = asio::detail::socket_ops::get_error(); bool is_read_needed = (error_code == SSL_ERROR_WANT_READ); bool is_write_needed = (error_code == SSL_ERROR_WANT_WRITE || ::BIO_ctrl_pending( ssl_bio_ )); @@ -165,9 +167,14 @@ if (!is_operation_done && !is_read_needed && !is_write_needed && !is_shut_down_sent) + { // The operation has failed... It is not completed and does // not want network communication nor does want to send shutdown out... - return handler_(asio::error(error_code), rc); + if (error_code == SSL_ERROR_SYSCALL) + return handler_(asio::error(sys_error_code), rc); + else + return handler_(asio::error(error_code + 1000000), rc); + } if (!is_operation_done && !is_write_needed) {
participants (2)
-
Christopher Kohlhoff
-
Scott