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

Graceful shutdown for runtime #708

Open
emil14 opened this issue Sep 26, 2024 · 2 comments
Open

Graceful shutdown for runtime #708

emil14 opened this issue Sep 26, 2024 · 2 comments
Assignees
Labels

Comments

@emil14
Copy link
Collaborator

emil14 commented Sep 26, 2024

When we click ctrl+c we terminate the neva process without handling it. What we probably should do is to close the context to make sure func-runner is gracefully terminated. It's possible to imagine a situation where some component (e.g. http get) opens a connection and never frees it after ctrl+c (or other termination signals from the OS)

Question is, shouldn't user do these kind of things manually? Why e.g. Go doesn't handle resource freeing automatically?

    // graceful shutdown for runtime
    ctx, cancel := context.WithCancel(context.Background())

    sigChan := make(chan os.Signal, 1)
    signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

    go func() {
        <-sigChan
        cancel()
    }()

Might be related to #668 and #811

@emil14 emil14 added the Major label Sep 26, 2024
@emil14 emil14 self-assigned this Sep 26, 2024
@default-writer
Copy link

In C# there are the concept of state in CancellationToken object, which holds both the result of any async operation or state of async function call. It is the obligatory of a programmer to check and to free resources in case of CancellationToken would contains cancellation event state, so that instructs programmer to interrupt code and do whatever it takes to bypass any functions long polling or execution and finish immediately without possible exception handling, it works like a charm in case you do not rely on exception handling and use old good messaging system which will keep working without making mad decisions with raising and handling errors in many places. In general exception raising and handing makes code less readable and less debuggable in my honest opinion.

@default-writer
Copy link

When we click ctrl+c we terminate the neva process without handling it. What we probably should do is to close the context to make sure func-runner is gracefully terminated. It's possible to imagine a situation where some component (e.g. http get) opens a connection and never frees it after ctrl+c (or other termination signals from the OS)

Question is, shouldn't user do these kind of things manually? Why e.g. Go doesn't handle resource freeing automatically?

    // graceful shutdown for runtime
    ctx, cancel := context.WithCancel(context.Background())

    sigChan := make(chan os.Signal, 1)
    signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

    go func() {
        <-sigChan
        cancel()
    }()

Might be related to #668 and #811

That reminds me of cancellation token in C#, definetely. And it looks like right approach but it needs to be widely supported alongside all base class libraries or replaced with syntaxical sugar so that tons of repeatetive code would goes away from the programmer's view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants