Skip to content

Fix leaked TLS handshake promise #180

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
merged 1 commit into from
Mar 12, 2020
Merged

Fix leaked TLS handshake promise #180

merged 1 commit into from
Mar 12, 2020

Conversation

PopFlamingo
Copy link
Contributor

@PopFlamingo PopFlamingo commented Mar 12, 2020

motivation:
TLS handshake promise was leaked in some cases of failure (fixes #179)

changes:

  • Avoid leaking promise
  • Clearer completion flow for related futures
  • Add testAvoidLeakingTLSHandshakeCompletionPromise test

@@ -383,32 +383,33 @@ final class ConnectionPool {
}

return channel.flatMap { channel -> EventLoopFuture<ConnectionPool.Connection> in
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, handshakePromise: handshakePromise).flatMap {
channel.pipeline.addSSLHandlerIfNeeded(for: self.key, tlsConfiguration: self.configuration.tlsConfiguration, handshakePromise: handshakePromise)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The promise and returned future were redundant IMO so this only makes use of handshakePromise now

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. Nice patch!

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! This looks really good, small suggestion for a better test

defer {
XCTAssertNoThrow(try httpClient.syncShutdown(requiresCleanClose: true))
}
XCTAssertThrowsError(try httpClient.get(url: "http://localhost/").wait()) { error in
Copy link
Contributor

Choose a reason for hiding this comment

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

this test isn't great. It relies on nothing being bound to port 80 on localhost. Can I suggest a slightly different strategy: Let's bind a random port with a server socket, then immediately close it and then connect that port instead and we have pretty high confidence that this port won't be bound by something else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@weissi Thank you! In cfba7e7, the refusesConnections: true option is now set on HTTPBin, I think it gives the behaviour we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops actually I don't think it does, I must still close it because the connection is still accepted it seems

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@weissi Latest push should be ok 🙂

motivation:
TLS handshake promise was leaked in some cases of failure (see #179)

changes:
- Avoid leaking promise
- Clearer completion flow for related futures
- Add testAvoidLeakingTLSHandshakeCompletionPromise test
@PopFlamingo PopFlamingo requested a review from weissi March 12, 2020 18:32
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.

looks great, thanks!

@weissi weissi merged commit 38bef7c into swift-server:master Mar 12, 2020
@PopFlamingo PopFlamingo deleted the fix-leaked-tls-promise branch March 13, 2020 16:13
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.

Leaking promise created at ConnectionPool.swift line 373
3 participants