我在server3上添加了ssl(asio示例)。在极少数情况下,当某些客户端握手失败并且计时器同时到期时,会发生SIGSEGV。
/ var / log / messages中的消息:
Aborted at 1517935343 (unix time) try "date -d @1517935343" if you are using GNU date <br>
PC: @ 0x41ff1b (unknown) <br>
SIGSEGV (@0x90) received by PID 32728 (TID 0x7f4b9fa79700) from PID 144; stack trace: <br>
0x30fbe0f7e0 (unknown) <br>
0x41ff1b (unknown) <br>
0x419b6a (unknown) <br>
0x41a6a7 (unknown) <br>
0x4229e2 (unknown) <br>
0x4239f2 (unknown) <br>
0x449f59 (unknown) <br>
0x44ca0f (unknown) <br>
0x44d488 (unknown) <br>
0x47defb (unknown) <br>
0x30fbe07aa1 (unknown) <br>
0x3f796e893d (unknown) <br>
0x0 (unknown) <br>
A child(32728) terminated, restart it <br>
connection_s.cpp
void connection_s::start()
{
//Start timer for monitoring this connectoin's timeout.
timer_.expires_from_now(boost::posix_time::seconds(20));
timer_.async_wait(boost::bind(&connection_s::handle_timeout, shared_from_this(), _1));
socket_.async_handshake(boost::asio::ssl::stream_base::server,
boost::bind(&connection_s::handle_handshake, shared_from_this(),
boost::asio::placeholders::error));
}
void connection_s::handle_handshake(const boost::system::error_code& e)
{
if (!e)
{
socket_.async_read_some(boost::asio::buffer(buffer_),
strand_.wrap(boost::bind(&connection_s::handle_read, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
} else {
//eof means that peer has cleanly closed the connection, so we need not to
//explicitly stop(shutdown) the connectoin.
LOG(ERROR) << "Handshake error:" << e.message();
timer_.cancel();
stop();
}
}
void connection_s::stop()
{
boost::system::error_code ignored_ec;
socket_.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
if (ignored_ec) {
LOG(ERROR) << "socket_.lowest_layer().shutdown error message : " << ignored_ec.message() << std::endl;
return;
}
socket_.lowest_layer().close(ignored_ec);
}
void connection_s::handle_timeout(const boost::system::error_code& e)
{
if (!e)
{
boost::system::error_code ec;
//boost::asio::ip::tcp::endpoint ep = socket().remote_endpoint(ec);
boost::asio::ip::tcp::endpoint ep = socket().lowest_layer().remote_endpoint(ec);
if (!ec)
{
LOG(WARNING) << "connection_s timeout:" << ep;
}
else
{
LOG(WARNING) << "connection_s timeout(unknow peer):" << ec.message();
}
stop();
}
}
我使用了connection_ptr管理connection_s的对象,是什么导致SIGSEGV?
谢谢。