-
Notifications
You must be signed in to change notification settings - Fork 125
Close idle pool connections #170
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
weissi
merged 18 commits into
swift-server:master
from
PopFlamingo:close-idle-connections
Mar 3, 2020
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2f8e252
Close idle pool connections
PopFlamingo abbd057
Transmit inbound events in IdlePoolConnectionHandler
PopFlamingo 6ccd28a
Fix testPoolClosesIdleConnections
PopFlamingo 2044699
Fix idle handle racing condition
PopFlamingo 060c277
Configuration property rename
PopFlamingo fdd9648
Fix config property name in tests
PopFlamingo 9559b3f
Fix redundant handler removal
PopFlamingo fa21e8b
Merge branch 'master' into close-idle-connections
PopFlamingo 6c23cf5
test delayed close
weissi 20e970c
Merge pull request #4 from weissi/jw-test-delay-close
adtrevor 44079a8
Fix delayed close race
PopFlamingo e6f2584
Fix warning
PopFlamingo 00a7ecd
Merge branch 'master' into close-idle-connections
adtrevor 30e2e30
fix test
a70e90a
Merge pull request #5 from weissi/trevor-pooling-fix
adtrevor 98e4886
Explain why we ignore .notFound error for the timeout handlers
PopFlamingo 87b6b5a
Add additional activity checks
PopFlamingo 9e9d3b7
Rename and invert timeoutClosed
PopFlamingo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,7 +305,7 @@ public class HTTPClient { | |
redirectHandler = nil | ||
} | ||
|
||
let task = Task<Delegate.Response>(eventLoop: taskEL) | ||
let task = Task<Delegate.Response>(eventLoop: taskEL, poolingTimeout: self.configuration.poolingTimeout) | ||
self.stateLock.withLock { | ||
self.tasks[task.id] = task | ||
} | ||
|
@@ -321,17 +321,18 @@ public class HTTPClient { | |
|
||
connection.flatMap { connection -> EventLoopFuture<Void> in | ||
let channel = connection.channel | ||
let addedFuture: EventLoopFuture<Void> | ||
|
||
switch self.configuration.decompression { | ||
case .disabled: | ||
addedFuture = channel.eventLoop.makeSucceededFuture(()) | ||
case .enabled(let limit): | ||
let decompressHandler = NIOHTTPResponseDecompressor(limit: limit) | ||
addedFuture = channel.pipeline.addHandler(decompressHandler) | ||
} | ||
|
||
return addedFuture.flatMap { | ||
return connection.removeHandler(IdleStateHandler.self).flatMap { | ||
connection.removeHandler(IdlePoolConnectionHandler.self) | ||
}.flatMap { | ||
switch self.configuration.decompression { | ||
case .disabled: | ||
return channel.eventLoop.makeSucceededFuture(()) | ||
case .enabled(let limit): | ||
let decompressHandler = NIOHTTPResponseDecompressor(limit: limit) | ||
return channel.pipeline.addHandler(decompressHandler) | ||
} | ||
}.flatMap { | ||
if let timeout = self.resolve(timeout: self.configuration.timeout.read, deadline: deadline) { | ||
return channel.pipeline.addHandler(IdleStateHandler(readTimeout: timeout)) | ||
} else { | ||
|
@@ -408,6 +409,8 @@ public class HTTPClient { | |
public var redirectConfiguration: RedirectConfiguration | ||
/// Default client timeout, defaults to no timeouts. | ||
public var timeout: Timeout | ||
/// Timeout of pooled connections | ||
public var poolingTimeout: TimeAmount? | ||
/// Upstream proxy, defaults to no proxy. | ||
public var proxy: Proxy? | ||
/// Enables automatic body decompression. Supported algorithms are gzip and deflate. | ||
|
@@ -418,30 +421,68 @@ public class HTTPClient { | |
public init(tlsConfiguration: TLSConfiguration? = nil, | ||
redirectConfiguration: RedirectConfiguration? = nil, | ||
timeout: Timeout = Timeout(), | ||
poolingTimeout: TimeAmount, | ||
proxy: Proxy? = nil, | ||
ignoreUncleanSSLShutdown: Bool = false, | ||
decompression: Decompression = .disabled) { | ||
self.tlsConfiguration = tlsConfiguration | ||
self.redirectConfiguration = redirectConfiguration ?? RedirectConfiguration() | ||
self.timeout = timeout | ||
self.poolingTimeout = poolingTimeout | ||
self.proxy = proxy | ||
self.ignoreUncleanSSLShutdown = ignoreUncleanSSLShutdown | ||
self.decompression = decompression | ||
} | ||
|
||
public init(tlsConfiguration: TLSConfiguration? = nil, | ||
redirectConfiguration: RedirectConfiguration? = nil, | ||
timeout: Timeout = Timeout(), | ||
proxy: Proxy? = nil, | ||
ignoreUncleanSSLShutdown: Bool = false, | ||
decompression: Decompression = .disabled) { | ||
self.init( | ||
tlsConfiguration: tlsConfiguration, | ||
redirectConfiguration: redirectConfiguration, | ||
timeout: timeout, | ||
poolingTimeout: .seconds(60), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of the default 60 seconds timeout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with this, @Lukasa ? |
||
proxy: proxy, | ||
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown, | ||
decompression: decompression | ||
) | ||
} | ||
|
||
public init(certificateVerification: CertificateVerification, | ||
redirectConfiguration: RedirectConfiguration? = nil, | ||
timeout: Timeout = Timeout(), | ||
poolingTimeout: TimeAmount = .seconds(60), | ||
proxy: Proxy? = nil, | ||
ignoreUncleanSSLShutdown: Bool = false, | ||
decompression: Decompression = .disabled) { | ||
self.tlsConfiguration = TLSConfiguration.forClient(certificateVerification: certificateVerification) | ||
self.redirectConfiguration = redirectConfiguration ?? RedirectConfiguration() | ||
self.timeout = timeout | ||
self.poolingTimeout = poolingTimeout | ||
self.proxy = proxy | ||
self.ignoreUncleanSSLShutdown = ignoreUncleanSSLShutdown | ||
self.decompression = decompression | ||
} | ||
|
||
public init(certificateVerification: CertificateVerification, | ||
redirectConfiguration: RedirectConfiguration? = nil, | ||
timeout: Timeout = Timeout(), | ||
proxy: Proxy? = nil, | ||
ignoreUncleanSSLShutdown: Bool = false, | ||
decompression: Decompression = .disabled) { | ||
self.init( | ||
certificateVerification: certificateVerification, | ||
redirectConfiguration: redirectConfiguration, | ||
timeout: timeout, | ||
poolingTimeout: .seconds(60), | ||
proxy: proxy, | ||
ignoreUncleanSSLShutdown: ignoreUncleanSSLShutdown, | ||
decompression: decompression | ||
) | ||
} | ||
} | ||
|
||
/// Specifies how `EventLoopGroup` will be created and establishes lifecycle ownership. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this a good name for this setting?
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.
I'd make it a bit longer and more descriptive. Maybe
maximumAllowedIdleTimeInConnectionPool
or so? @Lukasa ?Uh oh!
There was an error while loading. Please reload this page.
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.
Ok, I set it to this for now, thanks.