Tolerate the request stream being started after .finished (#577)

Motivation

The RequestBag intermediates between two different threads. This means
it can get requests that were reasonable when they were made but have
been superseded with newer information since then. These generally have
to be tolerated.

Unfortunately if we received a request to resume the request body stream
_after_ the need for that stream has been invalidated, we could hit a
crash. That's unnecessary, and we should tolerate it better.

Modifications

Tolerated receiving requests to resume body streaming in the finished
state.

Result

Fewer crashes
Fixes #576
This commit is contained in:
Cory Benfield
2022-04-11 11:13:56 +02:00
committed by GitHub
parent b1e4f1966a
commit f50bf983ea
3 changed files with 45 additions and 1 deletions
@@ -127,7 +127,11 @@ extension RequestBag.StateMachine {
return .none
case .finished:
preconditionFailure("Invalid state: \(self.state)")
// If this task has been cancelled we may be in an error state. As a matter of
// defensive programming, we also tolerate receiving this notification if we've ended cleanly:
// while it shouldn't happen, nothing will go wrong if we just ignore it.
// All paths through this state machine should cancel our request body stream to get here anyway.
return .none
case .modifying:
preconditionFailure("Invalid state: \(self.state)")