Skip to content
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

[Discussion] Add more connection failure tracking and tests. #7588

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yschimke
Copy link
Collaborator

Unlikely to be correct, but if the ConnectPlan is the right place, then a few more questions.

  • Are there more places for routeDatabase.failed?
  • Where should routeDatabase.connected be called?
  • Which exceptions indicate serious problems?

RealConnection.trackFailure doesn't look right for HTTP/2.

@@ -1022,6 +1022,8 @@ open class CallTest {
executeSynchronously(request)
.assertCode(200)
.assertBody("success!")

assertThat(client.routeDatabase.failedRoutes.single().proxy.address()).isEqualTo(server.toProxyAddress().address())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only failing test when routeDatabase.failed is not called. Seems like we are missing coverage.

Copy link
Member

Choose a reason for hiding this comment

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

Or perhaps, the coverage we do have (in RouteFailureTest) is overly pessimistic??

@yschimke
Copy link
Collaborator Author

Only failure from disabling the RouteDatabase tracking prior to this

CallTest[jvm] > readTimeoutFails()[jvm] FAILED
    java.lang.AssertionError: 
    Expecting actual not to be null
        at okhttp3.RecordedResponse.assertCode(RecordedResponse.java:61)
        at okhttp3.CallTest.readTimeoutFails(CallTest.kt:1023)

@@ -132,6 +132,7 @@ class ConnectPlan(
success = true
return ConnectResult(plan = this)
} catch (e: IOException) {
client.routeDatabase.failed(route)
Copy link
Member

Choose a reason for hiding this comment

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

This will also capture cases where the call was canceled. Hmm.

Copy link
Member

Choose a reason for hiding this comment

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

And looking at the other call to routeDatabase.failed(), I think we should notify the proxy selector.

This is from RealConnection.kt:

    // Tell the proxy selector when we fail to connect on a fresh connection.
    if (failedRoute.proxy.type() != Proxy.Type.DIRECT) {
      val address = failedRoute.address
      address.proxySelector.connectFailed(
        address.url.toUri(), failedRoute.proxy.address(), failure
      )
    }

Perhaps the nicest structure is to move that snippet out of RealConnection and into RouteDatabase, so the two are always in sync.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I wanted this to prompt discussion. I'm not clear that the current exception filtering is obviously right.

I'll split it out and use the opportunity to make a test.

.apply {
retryOnConnectionFailure = true
}
.build()

executeSynchronously(request)
.assertFailureMatches("stream was reset: REFUSED_STREAM")
.assertCode(200)
Copy link
Member

Choose a reason for hiding this comment

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

ooooh does your fix cause this to connect to a good host? That is PRETTY RAD

@@ -1022,6 +1022,8 @@ open class CallTest {
executeSynchronously(request)
.assertCode(200)
.assertBody("success!")

assertThat(client.routeDatabase.failedRoutes.single().proxy.address()).isEqualTo(server.toProxyAddress().address())
Copy link
Member

Choose a reason for hiding this comment

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

Or perhaps, the coverage we do have (in RouteFailureTest) is overly pessimistic??

# Conflicts:
#	okhttp/src/jvmTest/java/okhttp3/RouteFailureTest.kt
@yschimke yschimke marked this pull request as draft January 5, 2023 03:39
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.

None yet

2 participants