Skip to content
Snippets Groups Projects
Commit c690d060 authored by Seva's avatar Seva Committed by Adrien Béraud
Browse files

http: fix req cancel racing condition

parent bcf8ab54
Branches
Tags
No related merge requests found
...@@ -99,6 +99,7 @@ public: ...@@ -99,6 +99,7 @@ public:
void async_read(const size_t bytes, BytesHandlerCb cb); void async_read(const size_t bytes, BytesHandlerCb cb);
void timeout(const std::chrono::seconds timeout, HandlerCb cb = {}); void timeout(const std::chrono::seconds timeout, HandlerCb cb = {});
void close();
private: private:
unsigned int id_; unsigned int id_;
......
...@@ -117,20 +117,22 @@ Connection::Connection(asio::io_context& ctx, std::shared_ptr<dht::crypto::Certi ...@@ -117,20 +117,22 @@ Connection::Connection(asio::io_context& ctx, std::shared_ptr<dht::crypto::Certi
Connection::~Connection() Connection::~Connection()
{ {
close();
}
void
Connection::close()
{
if (!is_open())
return;
asio::error_code ec; asio::error_code ec;
if (is_open()){ if (ssl_ctx_)
if (ssl_ctx_){
ssl_socket_->cancel(ec);
ssl_socket_->close(ec); ssl_socket_->close(ec);
} else
else {
socket_->cancel(ec);
socket_->close(ec); socket_->close(ec);
}
if (ec and logger_) if (ec and logger_)
logger_->e("[http:client] [connection:%i] error closing: %s", id_, ec.message().c_str()); logger_->e("[http:client] [connection:%i] error closing: %s", id_, ec.message().c_str());
} }
}
unsigned int unsigned int
Connection::id() Connection::id()
...@@ -442,7 +444,7 @@ Request::~Request() ...@@ -442,7 +444,7 @@ Request::~Request()
void void
Request::cancel() Request::cancel()
{ {
terminate(asio::error::eof); conn_->close();
} }
unsigned int unsigned int
...@@ -899,8 +901,10 @@ Request::handle_response_header(const asio::error_code& ec) ...@@ -899,8 +901,10 @@ Request::handle_response_header(const asio::error_code& ec)
void void
Request::handle_response_body(const asio::error_code& ec, const size_t bytes) Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
{ {
if (ec == asio::error::operation_aborted) if (ec == asio::error::operation_aborted){
terminate(ec);
return; return;
}
else if ((ec == asio::error::eof) or (ec == asio::error::connection_reset)){ else if ((ec == asio::error::eof) or (ec == asio::error::connection_reset)){
terminate(ec); terminate(ec);
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment