-
Notifications
You must be signed in to change notification settings - Fork 349
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
Support forcing the proxy to accept new connections while max-sigterm-delay is in effect #1640
Comments
I'm curious about this:
Why is your app making a new database connection? Could you just re-use an existing connection with a connection pool for instance? |
Python Celery workers when processing jobs open/close new connections. Would that be possible to make the clousql proxy alive until the main container die? Maybe I'm missing something about configuring the way celery workers connect to cloudsql proxy with a connection pool. But it does not seems intuitive... |
Have you tried using the |
Hey @enocom -- Also encountering this as a change in behaviour between v1 and v2. When using The main thing I can see this impacting is apps that are using connection pools as they will not be able to lease new connections, which they would have previously. |
I don't want to try to kill the cloudsql proxy from another container right now. But maybe that would be a solution to explore. So I now have clousql proxy <- pgbouncer <- celery worker. Now what happen is that all pods receive a
Then cloudsql-proxy is closed and my celery worker throws error as it is still in graceful shutdown and need to access the database for storing last results before quitting. What is needed, is that "connection pool/cloudsql proxy" containers are shutdowned after the graceful period of the main container (celery worker in my case). This means potentially accepting new connections to the connection pool. So, maybe using the Maybe simply use the Thoughts? |
In theory, we could change the behavior to accept new connections when the max-sigterm-delay is in effect. I think it would amount to moving these lines down below the timer. |
Please see this post on this topic which refers to this Twitter thread from Tim Hockin which basically says that (at least within k8s) a pod / container should always keep accepting new connections even after a I found this very counterintuitive personally and this thread clarified things quite well: basically, shutting down gracefully is hard in k8s, so you can't really assume anything. As for this particular container, since it can run in varying contexts, perhaps this behaviour should be a flag, e.g.: |
Thanks for the links @plaflamme. I'm convinced we can just fix this. |
When the proxy starts its shut down, it will now accept additional connections when the max-sigterm-delay flag is passed. As before, if any connections are still open after the delay has elapsed, the Proxy will report an error. Fixes #1640.
When the proxy starts its shut down, it will now accept additional connections when the max-sigterm-delay flag is passed. As before, if any connections are still open after the delay has elapsed, the Proxy will report an error. Fixes #1640.
I'm having the same issues as OP, and I don't think the main concern has been addressed. At least, this is not what I'm seeing on my end. Using version 2.8.1. I'm also using What happens is that both the
Note that I only call What I need is the proxy to keep serving for a certain period of time, and not exit early if there are no connections, which I think is what @plaflamme was suggesting. |
I'm open to having the proxy wait the full duration regardless of how many open connections there are. Would that solve your use case @tcrasset? |
Yes, that would solve it! @enocom |
I ended up using a |
I think we can build-in support for that in the Proxy. We'll get to this. |
I think we need a new flag. These are the existing exit behavior flags:
Let's add a flag called The shutdown process:
|
Problem Case
Consider the following scenario when running the proxy as a sidecar in k8s:
term_timeout
ormax-sigterm-delay
is set for the proxy container to 5 minutesIt doesn't matter what you set the term_timeout to because the app needs to initiate new connections after both it and the proxy get a sigterm
Alternatives Considered
Hacky scripty entrypoint command that swallows sigterm and forces the proxy to remain up for a static amount of time to like the app container call the new quitquitquit endpoint
Proposed solution
What I suggest is this: The new quitquitquit supports an idle_timeout setting in the request. So the process could work like this:
term_timeout
ormax-sigterm-delay
is set for the proxy process to 5 minutesquitquitquit
endpoint of the proxy and setsidle_timeout
to 30 secondsterm_timeout
is still in effect but the proxy will allow new connections for 30 secondsWould it be easy to implement an arbitrary user set timer in the
quitquitquit
method?The text was updated successfully, but these errors were encountered: