-
-
Notifications
You must be signed in to change notification settings - Fork 396
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
quinn-proto: Chunks
panic-on-drop behavior is a footgun and makes control flow annoying
#1531
Comments
As a workaround, I'm calling |
Belatedly I have realized that panics not being printed out were my fault. My code was technically running as a test, so Cargo was buffering the output as it normally does, but I was not letting the test complete, as I was cancelling it early while watching the log output, which wasn't buffered. Still, my primary issue stands, that the panic doesn't need to happen. Worse yet, it's a |
Sorry for the trouble you've been having with our code! When we designed this we felt it was important to make sure callers use If you had gotten a full panic (plus backtrace) on your first test failures, would this have been as aggravating to you as it seems to have been now? |
I still had to restructure my code to make it not panic, so that was annoying regardless. If you're married to the |
I'm not "married" to the assert -- there's clearly a trade-off for which the best solution is not obvious to me, and I was asking for your feedback. |
My original point still stands: this is a low-level API, right? So why not assume the user knows what they're doing? It's certainly worth documenting that one should check for pending transmits after reading, because that might not immediately be obvious. Either way, documentation on the |
I also was bitten by this when writing tests that use Not sure what an alternative solution would be, just wanted to mention that in my eyes it wasn't very ergonomic. I ended up extracting the logic that used quinn/quinn-proto/src/tests/mod.rs Lines 2183 to 2194 in 3eb2636
|
Okay, I think I would be on board with removing the assertion in favor of better docs. Anyone want to submit a PR? |
Can this be assigned to me? I am new to contributing, so if anyone can guide me to the process that would be great. |
Sure -- what do you want to know? It's mostly just -- send a PR, ideally with small atomic commits each of which should be able to pass CI. |
Thanks, I have submitted PR 1703. Please could you kindly review the changes. I think I will have more questions later on as I get to contributing more to this project. |
Just ran into this again. It ends up being really annoying with control flow: 'inner: loop {
match chunks.next(MAX_CHUNK_SIZE) {
Ok(Some(chunk)) => {
// use `chunk`
}
Ok(None) => {
// Note: this needs to be called in every diverging branch
// or `chunks` will panic on-drop
let _ = chunks.finalize();
break 'outer;
},
Err(proto::ReadError::Blocked) => {
let _ = chunks.finalize();
break 'inner;
},
Err(proto::ReadError::Reset(code)) => {
let _ = chunks.finalize();
eyre::bail!("peer reset stream {stream_id:?} with code {code}");
}
}
} Since #1703 appears stalled, I may just open my own PR. |
I was just bitten by this assert while trying to debug a silent failure of my application during testing: https://github.com/quinn-rs/quinn/blob/main/quinn-proto/src/connection/streams/recv.rs#L289-L292
This was in a spawned Tokio task
which apparently suppresses the normal printing of panic backtraces to stderrand I was running this as a test which buffered the panic backtrace but not letting it complete. And I hadn't yet wired it up to check the task's exit status as it's supposed to be long-running anyway and I'm still working on the principal implementation here.On
StreamEvent::Opened
orStreamEvent::Readable
I essentially call into code that looks like this:As implied by the code here,
Notification
messages have a header that gives their length so we know how much data we need to buffer to fully decode them.reader
is the type that buffers chunks and implements the right traits forNotification::decode()
.Due to some bug in my code,
.try_peek_header()
is returning an error which normally would be logged when returned from this method. However, because theimpl Drop for Chunks
executes on the return, and because I hadn't called.finalize()
yet, this is turned into apanic!()
, which in the current state of my code just causes the task to silently exit.The thing is, I don't need the
ShouldTransmit
flag because this immediately returns to an event loop where I call all the appropriate.handle*()
and.poll*()
methods on thequinn_proto::Connection
. So the implicit finalize triggered by theDrop
impl would otherwise be sufficient for me.Because the panic message was being suppressed, it took me an annoyingly long time to figure this out. It wasn't until I ran the code in a debugger (which helpfully automatically breaks on panics) to figure this out. While I understand the point of the
debug_assert!()
is to teach the user how to use this API correctly, in my case it was much more of a hindrance than anything.(
Tokio's partly to blame here... why suppress backtraces in debug mode? That doesn't make any sense.However, the panic doesn't strictly need to happen either.quinn-proto
is by design a low-level API, so why is it assuming the user might not know what they're doing here?)The text was updated successfully, but these errors were encountered: