Skip to content

Commit

Permalink
Flush qlog streamer before closing the connection
Browse files Browse the repository at this point in the history
# Motivation
I was debugging some connection problems and enabled qlog; however, often I did not get output. My use-case is going through the FFI layer which instantiates a `BufferedWriter` for the file.
After looking through the code a bit it appears that the `QLogStreamer` is not flushed on all close paths which can lead to missing logs.

# Modification
Make sure that on every close path the streamer is flushed and closed as well.
  • Loading branch information
FranzBusch committed Dec 4, 2023
1 parent b0944d8 commit 5a97133
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
6 changes: 6 additions & 0 deletions qlog/src/streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ impl QlogStreamer {
}
}

impl Drop for QlogStreamer {
fn drop(&mut self) {
let _ = self.finish_log();
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
30 changes: 16 additions & 14 deletions quiche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ impl Connection {
if self.is_stateless_reset(&buf[len - left..len]) {
trace!("{} packet is a stateless reset", self.trace_id);

self.closed = true;
self.mark_closed();
}

left
Expand Down Expand Up @@ -5555,11 +5555,7 @@ impl Connection {
if draining_timer <= now {
trace!("{} draining timeout expired", self.trace_id);

qlog_with!(self.qlog, q, {
q.finish_log().ok();
});

self.closed = true;
self.mark_closed();
}

// Draining timer takes precedence over all other timers. If it is
Expand All @@ -5572,11 +5568,7 @@ impl Connection {
if timer <= now {
trace!("{} idle timeout expired", self.trace_id);

qlog_with!(self.qlog, q, {
q.finish_log().ok();
});

self.closed = true;
self.mark_closed();
self.timed_out = true;
return;
}
Expand Down Expand Up @@ -5630,11 +5622,13 @@ impl Connection {
Some(pid) =>
if self.set_active_path(pid, now).is_err() {
// The connection cannot continue.
self.closed = true;
self.mark_closed();
},

// The connection cannot continue.
None => self.closed = true,
None => {
self.mark_closed();
},
}
}
}
Expand Down Expand Up @@ -6059,7 +6053,7 @@ impl Connection {

// When no packet was successfully processed close connection immediately.
if self.recv_count == 0 {
self.closed = true;
self.mark_closed();
}

Ok(())
Expand Down Expand Up @@ -7436,6 +7430,14 @@ impl Connection {

Ok(pid)
}

// Marks the connection as closed and does any related tidyup.
fn mark_closed(&mut self) {
qlog_with!(self.qlog, q, {
q = None;

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / android_ndk_lts (armv7-linux-androideabi)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / android_ndk_lts (aarch64-linux-android)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche_ios (aarch64-apple-ios)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / android_ndk_lts (x86_64-linux-android)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche_multiarch (armv7-unknown-linux-gnueabihf)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche_multiarch (aarch64-unknown-linux-gnu)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche_multiarch (i686-unknown-linux-gnu)

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche_macos

mismatched types

Check failure on line 7437 in quiche/src/lib.rs

View workflow job for this annotation

GitHub Actions / quiche_windows (x86_64-pc-windows-gnu)

mismatched types
});
self.closed = true;
}
}

#[cfg(feature = "boringssl-boring-crate")]
Expand Down

0 comments on commit 5a97133

Please sign in to comment.