Skip to content

fix(cmd): use context.WithCancel to handle graceful shudowns #510

@sambhav-jain-16

Description

@sambhav-jain-16

Is your feature request related to a problem? Please describe.
Currently, every cmd code uses log.Fatal to handle the exit of the program, this is really bad since it calls os.Exit directly and it is very hard to implement a stopper in the cmd.Run function.

Describe the solution you'd like
Use context.WithCancel to pass a cancellable context, the underlying functions can call cancel in case of an error that requires the entire program to exit.
Then cmd.Run can have a exit handler that can listen to this context to gracefully clean up its resources.
This context can also be used by underlying functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    goPull requests that update Go codegood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions