-
Notifications
You must be signed in to change notification settings - Fork 125
notify delegate about connect errors #245
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
notify delegate about connect errors #245
Conversation
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.
LGTM.
let delegate = TestDelegate() | ||
let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get") | ||
do { | ||
try httpBin.shutdown() |
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 should be in an XCTAssertNoThrow
let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get") | ||
do { | ||
try httpBin.shutdown() | ||
_ = try httpClient.execute(request: request, delegate: delegate).wait() |
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.
please use
XCTThrowsError(try httpClient.execute(...).wait()) { error in
XCTAssert(...)
}
we literally had security issues before because of 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.
done, thank you for catching 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.
Sorry to request changes but it'd be great to use XCTAssert(No)Throw
instead of do {} catch {}
which is error prone (we had a security issue because of it)
@@ -562,7 +562,7 @@ class HTTP1ConnectionProvider { | |||
error = HTTPClient.NWErrorHandler.translateError(error) | |||
} | |||
#endif | |||
return self.eventLoop.makeFailedFuture(error) | |||
return eventLoop.makeFailedFuture(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.
think this is the wrong way around, no?
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.
No, I think this is correct, all channel related stuff should be on channel EL, not on providers default EL
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.
@artemredkin sorry, I meant from self.
to missing self
, eventLoop
isn't a local variable, is it?
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.
it is, yes, this is a channel EL, I can rename it to make it more obvious
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.
@artemredkin yes, I think that'd be a good idea tbh
@@ -562,7 +562,7 @@ class HTTP1ConnectionProvider { | |||
error = HTTPClient.NWErrorHandler.translateError(error) | |||
} | |||
#endif | |||
return self.eventLoop.makeFailedFuture(error) | |||
return eventLoop.makeFailedFuture(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.
@artemredkin sorry, I meant from self.
to missing self
, eventLoop
isn't a local variable, is it?
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.
Thank you! LGTM
Notify delegates about connect errors
Motivation:
When channel is established, all errors from that channel are piped into
didReceiveError
method of theHTTPClientReponseDelegate
, but connection errors are only delivered to task's promise. That behaviour might be confusing, since there could be cases where task and delegate observe different errors.Modifications:
Send error to delegate in addition to task's promise
Result:
Closes #242