Skip to content

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

Description

@naumov-andrey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions