You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
B-high-valueRepresents work that would have a big impactE-very-complexVery difficult. Do not attempt without significant relevant experience and motivation.
We should gradually phase out our use of unwrap() for graceful error handling or expect(). expect() should only be used for cases where an internal invariant has been violated. All values that go through or come from external crates should never have unwrap() or expect() called on them.
Reasoning: A web engine is an incredibly complicated piece of software that deals with unreliable, and often malicious, input. As much as possible, all operations should be considered fallible and failures handled as best as possible.
Reacted by Tim van der Lippe, Josh Bowman-Matthews, Ashwin Naren, TIN TUN AUNG, Taym Haddadi, Darkspirit, Geoffrey Parrier, Rui Pereira, cybai, Luke Warlow and 1 more
What about closed channels, if the channel was expected to live for the program lifetime?
I think in this particular case, we need to properly handle when one process or thread panics and needs to be restarted. That's one of the big benefits of isolating things to begin with.
I'm not too sure what we should do about lock poisoning.
expect() should only be used for cases where an internal invariant has been violated. All values that go through or come from external crates should never have unwrap() or expect() called on them.
This makes sense for release builds but I think we should keep panicking if cfg!(debug_assertions) is enabled whenever possible.
.expect() isn't a straightforward win. It can make bugs much harder to track down if they do occur as it doesn't produce a stack trace, there is no actual enforcement that the reason written in the expect() is valid, and it increases binary size as the assertion message is included in the final binary.
Hey, I would like to at least partially work on contributing to this issue, but had some questions before I just start with what I think is right.
So basically my questions sum up to the following:
What are the factors going into the decision of keeping an unwrap call for the time being?
What parts of the codebase should I focus on/which are higher priority?
Since this would be my first contribution to a big open source project, I very much hope I haven't done something outrageous by asking these questions here. If there is a more appropriate channel, I would appreciate nudging me in the right direction.
It can make bugs much harder to track down if they do occur as it doesn't produce a stack trace
What do you mean with this? It seems to me thatexpect panics like unwrap does, and that therefore it also produces a backtrace.
We also should be careful about blindly removing all expect/unwrap calls. In some specs you actually need to panic if you reach certain state. for example: the Streams spec follows a calling convention where ! means “unwrap” or “expect.” and and ? means result#36906 for reference.
We don't have to panic and bring down the whole process if such an assertion fails though. We could just throw an exception and abort.
It depends.
If the error was recoverable, then the spec would have been written in such a way. Having a process making essentially random progress from such a wrong state might be worse than crashing. And in the case of Servo, given its prototype development stage, we would benefit from the visibility of the crash, and the assertion that comes with it. Intermittent issues are harder to fix than crashes, because the intermittent issue requires identifying the broken invariant first, which is otherwise documented by the assertion.
If the error was recoverable, then the spec would have been written in such a way. Having a process making essentially random progress from such a wrong state might be worse than crashing. And in the case of Servo, given its prototype development stage, we would benefit from the visibility of the crash, and the assertion that comes with it. Intermittent issues are harder to fix than crashes, because the intermittent issue requires identifying the broken invariant first, which is otherwise documented by the assertion.
In this case I think a debug_assert! is the right behavior. In production mode Servo should not crash unless in some kind of unrecoverable situation, regardless of what the specification says. It's better to work outside the specification than to crash.
There was an invariant in place, so expect was the right thing to do because this wasn't a recoverable error, it was something that never should happen in production. A panic would prevent the PR from merging unless it maintained invariants.
If the expect would have been a debug assert, I doubt it would have been noticed. I'm not aware that we gate PR merges on an absence of debug asserts. Do we?
So I'm all for debug asserts, but only in expected cases. For example if you know that the send can fail because it is in fact normal for the receiving end to go away. See this example.
And I'll also all for introducing runtime recovery protocols where it would be useful.
But the point of an expect for an invariant is not to recover from it in production: it's the kind of problem that should be caught before merging a change.
If the expect would have been a debug assert, I doubt it would have been noticed. I'm not aware that we gate PR merges on an absence of debug asserts. Do we?
I'd be fine with using debug_assert instead of expect then. My main point is not: let's crash Servo; it is to have strong guardrails in place against regressions.
It seems like debug_assert could be a strong guardrail, but on the other hand it is already turned off in one place for performance reasons.
You'd also have to ensure problems are caught in debugging efforts for existing code, which are quite often noted via an issue that someone opens following a crash.
I think the focus should be on making efforts to fix problems in the code and ensuring invariant are maintained in the first place. There is some value in avoiding a crash in production by replacing an expect with a construct using debug_assert, but I think most value is in ensuring the code works before it ships to production. A running engine that doesn't crash but only works as intended some of the time is only marginally better than one that crashes.
I'll start using return debug_assert!(false, "Message"); as a pattern instead of doing an expect.
B-high-valueRepresents work that would have a big impactE-very-complexVery difficult. Do not attempt without significant relevant experience and motivation.
Activity
TimvdLippe commentedon Nov 20, 2025
unwrap()caused the Cloudflare outage this week: https://blog.cloudflare.com/18-november-2025-outage/jschwe commentedon Nov 20, 2025
IMHO that's not entirely fair to say, since the unwrap could have just as well been an expect, and the unwrap was quite far down the chain of issues.
Back on topic, probably we should discuss what this means in practice, for common occurrences of unwrapping:
In both cases, servo is probably crashing already, so at the very least those places might not be the highest impact to start removing unwrap()s from.
mrobinson commentedon Nov 20, 2025
I think in this particular case, we need to properly handle when one process or thread panics and needs to be restarted. That's one of the big benefits of isolating things to begin with.
I'm not too sure what we should do about lock poisoning.
jdm commentedon Nov 20, 2025
We could switch to parking_lot everywhere which doesn't use lock poisoning.
simonwuelker commentedon Nov 20, 2025
This makes sense for release builds but I think we should keep panicking if
cfg!(debug_assertions)is enabled whenever possible.chore: Use parking_lot Mutex and RwLock in net/ code
chore: Use parking_lot Mutex and RwLock in net/ code (#40805)
nicoburns commentedon Nov 22, 2025
.expect()isn't a straightforward win. It can make bugs much harder to track down if they do occur as it doesn't produce a stack trace, there is no actual enforcement that the reason written in theexpect()is valid, and it increases binary size as the assertion message is included in the final binary.EKQRCalamity commentedon Nov 24, 2025
Hey, I would like to at least partially work on contributing to this issue, but had some questions before I just start with what I think is right.
So basically my questions sum up to the following:
unwrapcall for the time being?Since this would be my first contribution to a big open source project, I very much hope I haven't done something outrageous by asking these questions here. If there is a more appropriate channel, I would appreciate nudging me in the right direction.
atouchet commentedon Nov 24, 2025
Are the labels on this issue correct? Both very-complex and good first issue seems a bit contradictory.
9 remaining items
Taym95 commentedon Nov 28, 2025
We also should be careful about blindly removing all
expect/unwrapcalls. In some specs you actually need to panic if you reach certain state. for example: the Streams spec follows a calling convention where!means “unwrap” or “expect.” and and?meansresult#36906 for reference.simonwuelker commentedon Nov 28, 2025
We don't have to panic and bring down the whole process if such an assertion fails though. We could just throw an exception and abort.
gterzian commentedon Dec 1, 2025
It depends.
If the error was recoverable, then the spec would have been written in such a way. Having a process making essentially random progress from such a wrong state might be worse than crashing. And in the case of Servo, given its prototype development stage, we would benefit from the visibility of the crash, and the assertion that comes with it. Intermittent issues are harder to fix than crashes, because the intermittent issue requires identifying the broken invariant first, which is otherwise documented by the assertion.
mrobinson commentedon Dec 1, 2025
In this case I think a
debug_assert!is the right behavior. In production mode Servo should not crash unless in some kind of unrecoverable situation, regardless of what the specification says. It's better to work outside the specification than to crash.simonwuelker commentedon Dec 2, 2025
A pattern I've used in #40945 is
fonts: Panic less in platform/freetype (#40945)
gterzian commentedon Dec 22, 2025
Here is a real-world example: #41437
There was an invariant in place, so
expectwas the right thing to do because this wasn't a recoverable error, it was something that never should happen in production. A panic would prevent the PR from merging unless it maintained invariants.If the expect would have been a debug assert, I doubt it would have been noticed. I'm not aware that we gate PR merges on an absence of debug asserts. Do we?
Re the above, the reason it merged despite breaking an invariant, is because we're not testing the multiprocess path in CI.
So I'm all for debug asserts, but only in expected cases. For example if you know that the send can fail because it is in fact normal for the receiving end to go away. See this example.
And I'll also all for introducing runtime recovery protocols where it would be useful.
But the point of an
expectfor an invariant is not to recover from it in production: it's the kind of problem that should be caught before merging a change.simonwuelker commentedon Dec 22, 2025
debug assertions are enabled in release builds:
servo/Cargo.toml
Lines 233 to 235 in 55c4f57
And release builds are what try runs use by default:
servo/python/servo/try_parser.py
Line 39 in 55c4f57
So CI would have failed with a
debug_assertin place.gterzian commentedon Dec 23, 2025
Ok, thanks for the info.
I'd be fine with using
debug_assertinstead ofexpectthen. My main point is not: let's crash Servo; it is to have strong guardrails in place against regressions.It seems like
debug_assertcould be a strong guardrail, but on the other hand it is already turned off in one place for performance reasons.You'd also have to ensure problems are caught in debugging efforts for existing code, which are quite often noted via an issue that someone opens following a crash.
I think the focus should be on making efforts to fix problems in the code and ensuring invariant are maintained in the first place. There is some value in avoiding a crash in production by replacing an
expectwith a construct usingdebug_assert, but I think most value is in ensuring the code works before it ships to production. A running engine that doesn't crash but only works as intended some of the time is only marginally better than one that crashes.I'll start using
return debug_assert!(false, "Message");as a pattern instead of doing anexpect./webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface/mediaElementAudioSource_volumeChange.html#43363canvas: Fix response panic on closed channel (servo#45310)
generic channel: Add `send_warn` / `send_ignore` helpers (servo#45311)
generic channel: Add `send_warn` / `send_ignore` helpers (servo#45311)
canvas: Fix response panic on closed channel (servo#45310)
canvas: Fix response panic on closed channel (#45310)