Skip to content

Add a way to check whether the context is being shut down #7701

@Keruspe

Description

@Keruspe

Is your feature request related to a problem? Please describe.
From within a library, I want to detect whether the tokio context from the calling application is being shutdown to properly clean things up instead of emitting undesired errors. Right now, I'm getting: Error { kind: IOError(Custom { kind: Other, error: "A Tokio 1.x context was found, but it is being shutdown." } which I then forward to the calling application.

Describe the solution you'd like
Something like handle.is_shutting_down() or even a basic tokio::is_shutdown_error(err) would be perfect to be able to handle this scenario.

Describe alternatives you've considered
Alternative is letting the application handle this, but this is only moving the problem around, I think.
I could also match on the error message, but it's not exported by tokio and might as well change at some point

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-feature-requestCategory: A feature request.M-runtimeModule: tokio/runtimeS-waiting-on-authorStatus: awaiting some action (such as code changes) from the PR or issue author.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions