styx icon indicating copy to clipboard operation
styx copied to clipboard

Sticky sessions remain pinned into to failed origins

Open mikkokar opened this issue 7 years ago • 2 comments

The problem

Sticky session stays pinned down to an origin even after that origin goes down.

The problem was introduced by our refactoring to prepare opening up an SPI interface for extending various styx components.

Sticky session pins down a nominated origin for an ongoing HTTP session. But when that origin goes down, the session must be migrated over to some other origin. The styx retry feature took care of this.

Detailed description

Root cause: retry passes the control back to the sticky session handler, which always tries again the same origin. That's why outcome.nextOrigin() always returns None in RetryOnErrorHandler code:

         if (!outcome.shouldRetry() || !outcome.nextOrigin().isPresent()) { 

Acceptance criteria

  • When an origin fails, any sticky sessions pinned to it must be migrated over to healthy origins

mikkokar avatar Jan 17 '18 12:01 mikkokar

Test case to demonstrate this issue:

  test("Routes to new origin when the origin indicated by sticky session cookie is no longer available.") {
    server1.stop()

    val client: StyxHttpClient = newHttpClientBuilder(
      new BackendService.Builder()
        .id(id("app"))
        .origins(appOriginOne, appOriginTwo)
        .stickySessionConfig(StickySessionEnabled)
        .build())
      .build

    val request: HttpRequest = Builder.get("/")
      .addCookie("styx_origin_app", "app-01")
      .build

    val response = waitForResponse(client.sendRequest(request))

    response.status() should be(OK)
    response.cookies() should have size (1)
    response.cookie("styx_origin_app").get().toString should fullyMatch regex "styx_origin_app=app-02; Max-Age=.*; Path=/; HttpOnly"
  }

mikkokar avatar Jan 17 '18 12:01 mikkokar

The typical use case for sticky-session cookies in Styx is when the downstream services also use sticky-sessions. If we switch the user to a different origin, they will lose their session. If the origin is only temporarily down, the user may prefer to retry (for a limited time) rather than immediately losing their session. Perhaps there should be a configurable number of failed requests before switching origins.

kvosper avatar Feb 22 '18 12:02 kvosper

Closing all issues over 3 years old. New issues can be created if problems are still occurring.

kvosper avatar Jan 11 '24 11:01 kvosper