-
Notifications
You must be signed in to change notification settings - Fork 30
fix: Use OkHttp EventLister
instead of ConnectionListener
for idle connection monitoring
#1312
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
52d84fd
Reimplement idle connection monitoring using `okhttp3.EventListener`
lauzadis e0e9680
Add changelog
lauzadis 57fda03
Upgrade to latest version of OkHttp
lauzadis 8c81ac9
Changelog
lauzadis e75ab3b
EventListenerChain
lauzadis 5355ea3
Create a single connection monitor, reuse it
lauzadis d5655eb
update comment
lauzadis 0480652
monospace
lauzadis 20d96f5
clenaup
lauzadis 44aa0ff
fix build
lauzadis c35e62d
ktlint
lauzadis b575879
Simplify connection monitoring listener registration
lauzadis 6dcb6af
add EventListenerChain tests
lauzadis 5ca0d1c
move test class to the bottom
lauzadis d5a8ce7
make EventListenerChain internal
lauzadis 4aa6b51
update cache events
lauzadis 02a051d
remove `poolOverride`
lauzadis d5a4b28
remove `poolOverride` apiDump
lauzadis 1e0dc1f
Use `connection` instead of `connId` in user-facing logging
lauzadis 9c42e30
Make ConnectionMonitoringEventListener `internal`
lauzadis 1f9b907
Revert "Upgrade to latest version of OkHttp"
lauzadis a23bef9
Revert "Changelog"
lauzadis ff9e771
Revert how `soTimeout` is updated
lauzadis d79cc34
Add missing letter
lauzadis d695ac5
Upgrade to OkHttp 5.1.0 and Okio 3.15.0
lauzadis 0457ba7
Merge branch 'v1.5-main' of github.com:smithy-lang/smithy-kotlin into…
lauzadis 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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "db001c20-3788-4cfe-9ec2-284fd86a80bd", | ||
"type": "bugfix", | ||
"description": "Reimplement idle connection monitoring using `okhttp3.EventListener` instead of now-internal `okhttp3.ConnectionListener`", | ||
"issues": [ | ||
"https://github.com/smithy-lang/smithy-kotlin/issues/1311" | ||
] | ||
} |
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
115 changes: 115 additions & 0 deletions
115
...-engine-okhttp/jvm/src/aws/smithy/kotlin/runtime/http/engine/okhttp/EventListenerChain.kt
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.smithy.kotlin.runtime.http.engine.okhttp | ||
|
||
import aws.smithy.kotlin.runtime.io.closeIfCloseable | ||
import okhttp3.* | ||
import java.io.IOException | ||
import java.net.InetAddress | ||
import java.net.InetSocketAddress | ||
import java.net.Proxy | ||
|
||
/** | ||
* An [okhttp3.EventListener] that delegates to a chain of EventListeners. | ||
* Start events are sent in forward order, terminal events are sent in reverse order | ||
*/ | ||
internal class EventListenerChain( | ||
private val listeners: List<EventListener>, | ||
) : EventListener() { | ||
private val reverseListeners = listeners.reversed() | ||
|
||
fun close() { | ||
listeners.forEach { | ||
it.closeIfCloseable() | ||
} | ||
} | ||
|
||
override fun callStart(call: Call): Unit = | ||
listeners.forEach { it.callStart(call) } | ||
|
||
override fun dnsStart(call: Call, domainName: String): Unit = | ||
listeners.forEach { it.dnsStart(call, domainName) } | ||
|
||
override fun dnsEnd(call: Call, domainName: String, inetAddressList: List<InetAddress>): Unit = | ||
reverseListeners.forEach { it.dnsEnd(call, domainName, inetAddressList) } | ||
|
||
override fun proxySelectStart(call: Call, url: HttpUrl): Unit = | ||
listeners.forEach { it.proxySelectStart(call, url) } | ||
|
||
override fun proxySelectEnd(call: Call, url: HttpUrl, proxies: List<Proxy>): Unit = | ||
reverseListeners.forEach { it.proxySelectEnd(call, url, proxies) } | ||
|
||
override fun connectStart(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy): Unit = | ||
listeners.forEach { it.connectStart(call, inetSocketAddress, proxy) } | ||
|
||
override fun secureConnectStart(call: Call): Unit = | ||
listeners.forEach { it.secureConnectStart(call) } | ||
|
||
override fun secureConnectEnd(call: Call, handshake: Handshake?): Unit = | ||
reverseListeners.forEach { it.secureConnectEnd(call, handshake) } | ||
|
||
override fun connectEnd(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?): Unit = | ||
reverseListeners.forEach { it.connectEnd(call, inetSocketAddress, proxy, protocol) } | ||
|
||
override fun connectFailed(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?, ioe: IOException): Unit = | ||
reverseListeners.forEach { it.connectFailed(call, inetSocketAddress, proxy, protocol, ioe) } | ||
|
||
override fun connectionAcquired(call: Call, connection: Connection): Unit = | ||
listeners.forEach { it.connectionAcquired(call, connection) } | ||
|
||
override fun connectionReleased(call: Call, connection: Connection): Unit = | ||
reverseListeners.forEach { it.connectionReleased(call, connection) } | ||
|
||
override fun requestHeadersStart(call: Call): Unit = | ||
listeners.forEach { it.requestHeadersStart(call) } | ||
|
||
override fun requestHeadersEnd(call: Call, request: Request): Unit = | ||
reverseListeners.forEach { it.requestHeadersEnd(call, request) } | ||
|
||
override fun requestBodyStart(call: Call): Unit = | ||
listeners.forEach { it.requestBodyStart(call) } | ||
|
||
override fun requestBodyEnd(call: Call, byteCount: Long): Unit = | ||
reverseListeners.forEach { it.requestBodyEnd(call, byteCount) } | ||
|
||
override fun requestFailed(call: Call, ioe: IOException): Unit = | ||
reverseListeners.forEach { it.requestFailed(call, ioe) } | ||
|
||
override fun responseHeadersStart(call: Call): Unit = | ||
listeners.forEach { it.responseHeadersStart(call) } | ||
|
||
override fun responseHeadersEnd(call: Call, response: Response): Unit = | ||
reverseListeners.forEach { it.responseHeadersEnd(call, response) } | ||
|
||
override fun responseBodyStart(call: Call): Unit = | ||
listeners.forEach { it.responseBodyStart(call) } | ||
|
||
override fun responseBodyEnd(call: Call, byteCount: Long): Unit = | ||
reverseListeners.forEach { it.responseBodyEnd(call, byteCount) } | ||
|
||
override fun responseFailed(call: Call, ioe: IOException): Unit = | ||
reverseListeners.forEach { it.responseFailed(call, ioe) } | ||
|
||
override fun callEnd(call: Call): Unit = | ||
reverseListeners.forEach { it.callEnd(call) } | ||
|
||
override fun callFailed(call: Call, ioe: IOException): Unit = | ||
reverseListeners.forEach { it.callFailed(call, ioe) } | ||
|
||
override fun canceled(call: Call): Unit = | ||
reverseListeners.forEach { it.canceled(call) } | ||
|
||
override fun satisfactionFailure(call: Call, response: Response): Unit = | ||
reverseListeners.forEach { it.satisfactionFailure(call, response) } | ||
|
||
override fun cacheConditionalHit(call: Call, cachedResponse: Response): Unit = | ||
listeners.forEach { it.cacheConditionalHit(call, cachedResponse) } | ||
|
||
override fun cacheHit(call: Call, response: Response): Unit = | ||
listeners.forEach { it.cacheHit(call, response) } | ||
|
||
override fun cacheMiss(call: Call): Unit = | ||
listeners.forEach { it.cacheMiss(call) } | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Nit: This comment isn't accurate anymore
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.
Yes it is. We are creating our own pool using timeout settings taken from config