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

Gracefully resolve shutdown #67

Open
fubuloubu opened this issue Apr 10, 2024 · 1 comment · May be fixed by #78
Open

Gracefully resolve shutdown #67

fubuloubu opened this issue Apr 10, 2024 · 1 comment · May be fixed by #78
Assignees

Comments

@fubuloubu
Copy link
Member

fubuloubu commented Apr 10, 2024

It looks to me like we have 1 connection to the message broker per application. If so, then we need to add a task to the task queue that handles the connection termination prior to the application terminating so we don't have accidental open connections remaining.

import signal

class SigtermHandler:

    def __init__(self):
        self.should_terminate = False
        signal.signal(signal.SIGTERM, self._set_terminate)

    def _set_terminate(self):
        self.should_terminate = True

    def check_quit_signal(self):
        return self.should_terminate
def __init__(self):
    ...
    self.sigterm_handler = SigtermHandler

async def close_conn(self): # Add this method to the list of tasks that you run in the gather
    while not self.sigterm_handler.check_quit_signal():
        await.sleep(1)
    terminate_connection()  # some function to terminate connection to message broker

This is the basic idea of this, I'll keep reviewing to make sure I'm not completely off base here. But this is what I've done with Kafka and with RabbitMQ in Python

That seems reasonable

Just to lay out what we have going on here, we have a couple of different things in motion that need to gracefully shutdown:

  • broker needs to stop producing tasks (tasks are created based on RPC subscriptions module)
  • RPC subscriptions should be independently unsubscribed (so they stop producing new tasks)
  • websocket connections (that provide conduict for RPC subscriptions to come in) should be disconnected
  • all pending tasks should be finished (using the silverback worker command this is a separate process)
  • finally, we can exit Runner.run() method

@mikeshultz is working on some of this for the cluster (chat more offline about what the needs are there e.g. upgrading worker process to a new revision of the container), so I think it'd be great to collab more about what a "proper shutdown" scenario looks like, both for local dev (here in this SDK) and for the cluster (talk more about that outside of github)

Originally posted by @fubuloubu in #65 (comment)

Copy link

linear bot commented Apr 10, 2024

@fubuloubu fubuloubu linked a pull request May 4, 2024 that will close this issue
4 tasks
@fubuloubu fubuloubu self-assigned this Jun 13, 2024
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 a pull request may close this issue.

1 participant