Skip to content

Commit

Permalink
Fix segfault and assert fail
Browse files Browse the repository at this point in the history
A segfault occured at quic connection close, when _quic_session was
reset, but packets where still comming.
An assert fail occured when receive_data was called on a close()'d quic
session.
Some extraneous prints removed.
  • Loading branch information
VanStratum committed Jun 21, 2021
1 parent c1b2d18 commit 1f114ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 2 additions & 5 deletions flame/quicsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void QUICSession::close()
void QUICSession::receive_data(const char data[], size_t len, const uvw::Addr *src_addr)
{
size_t off = 0;
assert(q_conn);
if (!q_conn)
return;

/* split UDP datagram into multiple QUIC packets */
while (off < len) {
Expand Down Expand Up @@ -226,11 +227,7 @@ void QUICSession::q_on_closed_by_remote(quicly_closed_by_remote_t *self, quicly_
";frame=" << PRIu64 << frame_type << ";reason=" << std::string(reason, reason_len) << std::endl;
}
} else if (QUICLY_ERROR_IS_QUIC_APPLICATION(err)) {
std::cerr << "application close:code=0" << PRIx16 << QUICLY_ERROR_GET_ERROR_CODE(err) <<
";reason=" << std::string(reason, reason_len) << std::endl;
} else if (err == QUICLY_ERROR_RECEIVED_STATELESS_RESET) {
std::cerr << "stateless reset" << std::endl;
} else if (err == QUICLY_ERROR_NO_COMPATIBLE_VERSION) {
std::cerr << "no compatible version" << std::endl;
} else {
std::cerr << "unexpected close:code=" << PRIu16 << err << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions flame/quicsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class QUICSession {
quicly_cid_plaintext_t cid);
virtual ~QUICSession();

/*
* Close the session and the underlying connection.
* Depending on the state of the session, the close will be graceful or abrut
*/
virtual void close();
virtual void receive_data(const char data[], size_t len, const uvw::Addr *src_addr);
/*
Expand Down
9 changes: 5 additions & 4 deletions flame/trafgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ void TrafGen::start_quic()
_metrics->trafgen_id(_udp_handle->sock().port);

_udp_handle->on<uvw::UDPDataEvent>([this](const uvw::UDPDataEvent &event, uvw::UDPHandle &h) {
_quic_session->receive_data(event.data.get(), event.length, &event.sender);
if (_quic_session)
_quic_session->receive_data(event.data.get(), event.length, &event.sender);
});

_udp_handle->recv();
Expand Down Expand Up @@ -478,14 +479,14 @@ void TrafGen::start()
#ifdef QUIC_ENABLE
else if (_traf_config->protocol == Protocol::QUIC) {
_shutdown_timer->on<uvw::TimerEvent>([this](auto &, auto &) {
if (_udp_handle.get())
_udp_handle->stop();
if (_quic_session.get())
_quic_session->close();

_timeout_timer->stop();
if (_udp_handle.get()) {
_udp_handle->stop();
if (_udp_handle.get())
_udp_handle->close();
}
_timeout_timer->close();
_shutdown_timer->close();
this->handle_timeouts();
Expand Down

0 comments on commit 1f114ea

Please sign in to comment.