Skip to content

Commit d021e8c

Browse files
authored
fix: Stream debug impl to not print Waker (#840)
This implements a custom `Debug` impl for `Stream` so that the `Waker` type stored in the `*_task` fields does not get printed. This is because the `Debug` impl of `Waker` prints a pointer which is non-deterministic. My use-case here is that I am trying to make turmoil deterministic and testing it with h2 via comparing trace logs between two same seeded runs.
1 parent e9ee0b6 commit d021e8c

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/proto/streams/stream.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::Reason;
22

33
use super::*;
44

5+
use std::fmt;
56
use std::task::{Context, Waker};
67
use std::time::Instant;
78

@@ -16,7 +17,6 @@ use std::time::Instant;
1617
/// It's important to note that when the stream is placed in an internal queue
1718
/// (such as an accept queue), this is **not** tracked by a reference count.
1819
/// Thus, `ref_count` can be zero and the stream still has to be kept around.
19-
#[derive(Debug)]
2020
pub(super) struct Stream {
2121
/// The h2 stream identifier
2222
pub id: StreamId,
@@ -391,6 +391,47 @@ impl Stream {
391391
}
392392
}
393393

394+
impl fmt::Debug for Stream {
395+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
396+
f.debug_struct("Stream")
397+
.field("id", &self.id)
398+
.field("state", &self.state)
399+
.field("is_counted", &self.is_counted)
400+
.field("ref_count", &self.ref_count)
401+
.field("next_pending_send", &self.next_pending_send)
402+
.field("is_pending_send", &self.is_pending_send)
403+
.field("send_flow", &self.send_flow)
404+
.field("requested_send_capacity", &self.requested_send_capacity)
405+
.field("buffered_send_data", &self.buffered_send_data)
406+
.field("send_task", &self.send_task.as_ref().map(|_| ()))
407+
.field("pending_send", &self.pending_send)
408+
.field(
409+
"next_pending_send_capacity",
410+
&self.next_pending_send_capacity,
411+
)
412+
.field("is_pending_send_capacity", &self.is_pending_send_capacity)
413+
.field("send_capacity_inc", &self.send_capacity_inc)
414+
.field("next_open", &self.next_open)
415+
.field("is_pending_open", &self.is_pending_open)
416+
.field("is_pending_push", &self.is_pending_push)
417+
.field("next_pending_accept", &self.next_pending_accept)
418+
.field("is_pending_accept", &self.is_pending_accept)
419+
.field("recv_flow", &self.recv_flow)
420+
.field("in_flight_recv_data", &self.in_flight_recv_data)
421+
.field("next_window_update", &self.next_window_update)
422+
.field("is_pending_window_update", &self.is_pending_window_update)
423+
.field("reset_at", &self.reset_at)
424+
.field("next_reset_expire", &self.next_reset_expire)
425+
.field("pending_recv", &self.pending_recv)
426+
.field("is_recv", &self.is_recv)
427+
.field("recv_task", &self.recv_task.as_ref().map(|_| ()))
428+
.field("push_task", &self.push_task.as_ref().map(|_| ()))
429+
.field("pending_push_promises", &self.pending_push_promises)
430+
.field("content_length", &self.content_length)
431+
.finish()
432+
}
433+
}
434+
394435
impl store::Next for NextAccept {
395436
fn next(stream: &Stream) -> Option<store::Key> {
396437
stream.next_pending_accept

0 commit comments

Comments
 (0)