Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev) Fix stream segfault; downgrade common warning logs #144

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace oxen::quic

if (!cptr)
{
log::warning(log_cat, "Error: connection could not be created");
log::info(log_cat, "Incoming connection was not accepted (likely an expired connection ID)");
return;
}

Expand Down Expand Up @@ -534,7 +534,7 @@ namespace oxen::quic
now);
rv != 0)
{
log::warning(log_cat, "Server could not verify regular token!");
log::info(log_cat, "Server could not verify regular token!");
return false;
}

Expand All @@ -560,7 +560,7 @@ namespace oxen::quic
now);
rv != 0)
{
log::warning(log_cat, "Server could not verify retry token!");
log::info(log_cat, "Server could not verify retry token!");
return false;
}

Expand Down
32 changes: 29 additions & 3 deletions src/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,41 @@ namespace oxen::quic
if (data.empty())
return;

// If we aren't currently in the event loop then we need to keep a weak pointer to the
// stream so that, when the below lambda gets processed, we can tell whether the stream is
// still actually alive. (But if we're already in the event loop the lambda fires
// immediately and we don't want to have to do an extra refcount increment/decrement).
std::optional<std::weak_ptr<Stream>> wself;
if (!endpoint.in_event_loop())
wself = weak_from_this();

// In theory, `endpoint` that we use here might be inaccessible as well, but unlike conn
// (which we have to check because it could have been closed by remote actions or network
// events) the application has control and responsibility for keeping the network/endpoint
// alive at least as long as all the Connections/Streams that instances that were attached
// to it.
endpoint.call([this, data, ka = std::move(keep_alive)]() {
if (!_conn || _conn->is_closing() || _conn->is_draining())
endpoint.call([this, wself = std::move(wself), data, ka = std::move(keep_alive)]() {
std::shared_ptr<Stream> sself;
if (wself)
{
// send() was called from outside the event loop, so check to make sure the stream
// is still alive (and thus `this` is still valid):
if (!(sself = wself->lock()))
{
log::debug(log_cat, "Stream has gone away, dropping send data");
return;
}
}
// else send() was already inside the event loop and thus `this` is still valid

if (_is_closing || _is_shutdown || _sent_fin)
{
log::debug(log_cat, "Stream {} is closing/shutting down, dropping send data", _stream_id);
return;
}
else if (!_conn || _conn->is_closing() || _conn->is_draining())
{
log::warning(log_cat, "Stream {} unable to send: connection is closed", _stream_id);
log::debug(log_cat, "Stream {} unable to send: connection is closed", _stream_id);
return;
}
log::trace(log_cat, "Stream (ID: {}) sending message: {}", _stream_id, buffer_printer{data});
Expand Down