Skip to content

Http and tls services are not initialized and terminated correctly  #13720

Closed

Description

@davidhadas

Without TLS, 3 http servers are created:

  • main
  • metrics
  • admin

The admin and the main have a drainer.

When the queue is asked to exit, drainer.Drain() is used to wait for 30s, after the 30s:

  • metrix is asked to Shutdown() (and exists)
  • admin is asked to Shutdown() (and exists)
  • queue completes termination and flush
    Note that main never asked to Shutdown() and never exists!! does this mean there may still be connections being served?
    Note also that Shutdown is performed without timeout and can wait indefinitely.

With TLS, 2 http servers are created:

  • main
  • metrics
    And 2 tls servers are created:
  • tlsMain
  • tlsAdmin

The main have a drainer.
The tlsMain have a second, unrelated drainer that is never being used. Lets call it drainerTls.

When the queue is asked to exit, drainer.Drain() is used to wait for 30s, after the 30s:

  • metrix is asked to Shutdown() (and exists)
  • queue completes termination and flush
    Note that drainerTls.Drain() was never called, the tlsMain and the tlsAdmin were never Shutdown and never exited before queue exists, Also, as before, main never Shutdown() and never exit as well.
    Again, note also that Shutdown is performed without timeout and can wait indefinitely.

The code comment indicates:

   // Removing the main server from the shutdown logic as we've already shut it down.
   delete(httpServers, "main")

But it is unclear where is it being shutdown.

The code comment also:

// TODO: The drain created with mainServer above is lost. Unify the two drain.

Which is inline with my reading

The code comment also:

        // Drop admin http server as we Use TLS for the admin server.
       ...
	//	delete(httpServers, "admin")

Why do we not also drop the admin, while we use tlsAdmin?

Activity

  1. added
    kind/bug
    on Feb 20, 2023
  2. davidhadas commented on Feb 20, 2023

    @davidhadas
    ContributorAuthor

    /assign @davidhadas

  3. davidhadas commented on Feb 20, 2023

    @davidhadas
    ContributorAuthor

    (removed)

  4. davidhadas commented on Feb 20, 2023

    @davidhadas
    ContributorAuthor

    I have confirmed that main continues to serve open connections after flush()
    I have confirmed that main continues to accept new connections after flush()

  5. changed the title [-]Drainer seem to not work correctly[/-] [+]Http and tls services are not initialized and terminated correctly [/+] on Feb 21, 2023
  6. added
    triage/accepted
    on Mar 8, 2023
  7. dprotaso commented on Mar 29, 2023

    @dprotaso
    Member

    Closing as per #13723 (comment)

  8. added this to the v1.10.0 milestone on Mar 30, 2023
  9. dermasmid commented on Mar 30, 2023

    @dermasmid

    i have been running into an issue with v1.9
    that when a pod was marked for deletion any active requests would be dropped (after the 30s wait), even if the timeoutSeconds was set to 600.
    the shutdown logs i would see were

    Attached drain handler from user-container&{GET /wait-for-drain HTTP/1.1 1 1 map[Accept-Encoding:[gzip] Referer:[http://10.122.14.239:8022//wait-for-drain] User-Agent:[Go-http-client/1.1]] {} <nil> 0 [] false 10.122.14.239:8022 map[] map[] <nil> map[] 10.122.14.1:54218 /wait-for-drain <nil> <nil> <nil> 0xc00001aac0}
    Received TERM signal, attempting to gracefully shutdown servers.
    Shutting down server: metrics
    Shutting down server: admin
    Shutdown complete, exiting...
    

    now the Shutdown complete would show up while my long running request was still in progress, and right after the queue-proxy container shut down, is when i would receive an error response (sometimes EOF sometimes dial tcp <pod-ip>:8012: connect: connection refused) this is also if i made sure my user container is not handling SIGTERM's and not shutting down.

    after testing the nightly build (gcr.io/knative-nightly/knative.dev/serving/cmd/queue@sha256:454d02ee2d84965e44068b4c658e80299af98159e0fc362888c3303cfd8631f4) this was fixed. my theory is that the main server was never Shutdown (which does wait for in flight reqs) and the drainer does not seem to handle this either, which means any requests still running after the 30s wait will error out.
    this was fixed in #13815
    note that i did not test this on a clean install and dont have a clear repro script, but if my assumptions are right, repro'ing this is just a matter of calling a long running endpoint and killing the pod that got that request.
    thanks @dprotaso for jumping on so quickly to help out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugtriage/accepted

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions