mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
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:
@@ -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)")
|
||||
|
||||
Reference in New Issue
Block a user