-
Notifications
You must be signed in to change notification settings - Fork 123
Fix state reverting #298
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
Fix state reverting #298
Conversation
3d48ccc
to
91c7263
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broadly looks good, I've left a couple of notes in the diff.
if !head.isKeepAlive { | ||
self.closing = true | ||
} | ||
switch self.state { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may read more clearly as:
if case .endOrError = self.state {
return
}
Rather than forcing the indentation of the rest of the body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! thank you, always forget about this pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the only place you didn't apply this pattern was this block? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
self.state = .bodySent | ||
if let expectedBodyLength = self.expectedBodyLength, expectedBodyLength != self.actualBodyLength { | ||
let error = HTTPClientError.bodyLengthMismatch | ||
self.errorCaught(context: context, error: error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need errorCaught
here: the future chain will call this code path anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
91c7263
to
21c826f
Compare
Motivation: Right now if task handler encounters an error, it changes state to `.endOrError`. We gate on that state to make sure that we do not process errors in the pipeline twice. Unfortunately, that state can be reset when we upload body or receive response parts. Modifications: Adds state validation before state is updated to a new value Adds a test Result: Fixes swift-server#297
21c826f
to
c7b67e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, looks great.
Prevent TaskHandler state change after
.endOrError
Motivation:
Right now if task handler encounters an error, it changes state to
.endOrError
. We gate on that state to make sure that we do not process errors in the pipeline twice. Unfortunately, that state can be reset when we upload body or receive response parts.Modifications:
Adds state validation before state is updated to a new value
Adds a test
Result:
Fixes #297