Skip to content

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

Merged

Conversation

artemredkin
Copy link
Collaborator

Notify delegates about connect errors

Motivation:
When channel is established, all errors from that channel are piped into didReceiveError method of the HTTPClientReponseDelegate, 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

@artemredkin artemredkin requested a review from weissi June 13, 2020 17:58
@artemredkin artemredkin added this to the 1.2.0 milestone Jun 15, 2020
Copy link
Collaborator

@Lukasa Lukasa left a 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()
Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Collaborator Author

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!

Copy link
Contributor

@weissi weissi left a 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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM

@artemredkin artemredkin merged commit aac4357 into swift-server:master Jun 23, 2020
@artemredkin artemredkin deleted the notify_delegate_on_connect_errors branch June 23, 2020 14:00
artemredkin added a commit to artemredkin/async-http-client that referenced this pull request Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTPClientResponseDelegate is not notified of some errors (connection related?).
3 participants