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

Deadlock calling Event in after-event callback when current state == dst #102

Open
naumov-andrey opened this issue Nov 21, 2023 · 0 comments

Comments

@naumov-andrey
Copy link

Hi,
I have a deadlock when trying to initiate transition in after-event callback for dst == src

Simpliest example

package main

import (
	"context"
	"fmt"

	"github.com/looplab/fsm"
)

func main() {
	fsm := fsm.NewFSM(
		"start",
		fsm.Events{
			{Name: "created", Src: []string{"start"}, Dst: "start"},
			{Name: "checked", Src: []string{"start"}, Dst: "checked"},
		},
		fsm.Callbacks{
			"after_created": func(ctx context.Context, e *fsm.Event) {
				// some checks
				if err := e.FSM.Event(ctx, "checked"); err != nil {
					fmt.Println(err)
				}
			},
		},
	)

	if err := fsm.Event(context.Background(), "created"); err != nil {
		panic(fmt.Sprintf("Error encountered when triggering the run event: %v", err))
	}
}

It seems to be a bag that there is no eventMu.Unlock() for an event without state transition
fsm.go#L335

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

No branches or pull requests

1 participant