-
Notifications
You must be signed in to change notification settings - Fork 120
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 bodyLengthMissmatch
error handling
#490
Conversation
df9b524
to
e097940
Compare
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0)) | ||
XCTAssertEqual(state.startRequest(head: requestHead, metadata: metadata), .sendRequestHead(requestHead, startBody: false)) | ||
|
||
XCTAssertEqual(state.errorHappened(ArbitraryError()), .failRequest(ArbitraryError(), .close)) |
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.
The error is not included in the Equatable conformance. To make sure you will need to unwrap the enum with a guard and make the error equatable.
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.
okay... but we have 18 places where we need to fix this.
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.
doing it correctly here is a start ;)
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 all of them :)
because `HTTPRequestStateMachine.Action` Equatable conformance ignores the error completly
guard case .failRequest(let error, .close) = state.requestCancelled() else { | ||
return XCTFail("unexpected action") | ||
} | ||
XCTAssertEqual(error as? HTTPClientError, .cancelled) |
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.
Previously we checked for .remoteConnectionClosed
but that was probably wrong and I think we actually wanted to check for .cancel
.
This reverts commit 3a6a256.
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.
Great work! Thanks! Tests should pass though!
Motivation
If we detect that a user tries to write more bytes as initially specified, we fail the request with a
HTTPClientError. bodyLengthMissmatch
. However, we forgot to update our internal state that the request is failed. One way this manifests is that subsequent errors are also propagated through the stack but should be silently ignored because the request is already failed.In addition, two compound cases in the switch statement inside of
errorHappened(_:)
had a where clause which did only apply to the last case but should have applied to each compound cases. This affects thebodyLengthMissmatch
error handling but also all error handling because errors were sometimes treated asNIOSSLError.uncleanShutdown
even if they were something completely different.Changes
.bodyLengthMissmatch
errorNIOSSLError.uncleanShutdown