Skip to content

state machine bug: calls shutdown if start fails #103

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

Closed
weissi opened this issue Jul 8, 2021 · 2 comments · Fixed by #107
Closed

state machine bug: calls shutdown if start fails #103

weissi opened this issue Jul 8, 2021 · 2 comments · Fixed by #107
Labels
kind/bug Feature doesn't work as expected.

Comments

@weissi
Copy link
Collaborator

weissi commented Jul 8, 2021

consider this code

        service.register(label: "thing",
                         start: .sync {
            print("THIS WILL FAIL")
            struct SomeError: Error {}
            throw SomeError()
        },
                         shutdown: .sync {
            print("SHUTDOWN <<< SHOULD NEVER HAPPEN")
        },
        shutdownIfNotStarted: false)

        try service.startAndWait()

clearly, it should never invoke the shutdown handler because the start one failed but it still will. It prints:

THIS WILL FAIL
SHUTDOWN <<< SHOULD NEVER HAPPEN
@weissi weissi added the kind/bug Feature doesn't work as expected. label Jul 8, 2021
@tomerd
Copy link
Contributor

tomerd commented Jul 8, 2021

@weissi iirc the design thought was that you may have created some state before failing that you want to clean up. obviously this is not always the case. is this behavior causing you issues? ideas on how to trade these off?

@weissi
Copy link
Collaborator Author

weissi commented Jul 9, 2021

@weissi iirc the design thought was that you may have created some state before failing that you want to clean up. obviously this is not always the case. is this behavior causing you issues? ideas on how to trade these off?

I thought the idea was that if you have created the state already, then you use registerShutdown which will unconditionally be called. But if you use register(..., start:, shutdown:) then I would've expected shutdown not to be called if start failed. Is there a situation where you would want shutdown to be called when start failed?

Especially given that I set shutdownIfNotStarted: false I really wouldn't have expected it to shut down if start failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected.
Projects
None yet
2 participants