statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
27.21k stars 1.26k forks source link

Bug: spawn actor on logger be alive after throwing an js error #5088

Open betterRunner opened 2 months ago

betterRunner commented 2 months ago

XState version

XState version 5

Description

Hi there, I made an experiment to test if a child spawn actor can restore nornal status after throwing an error, here is the process:

  1. A parent actor creates a spawn actor:

      childrenActorRef: ({ self, spawn }) => ({
      }),
    }),
  2. And I manually throw an error in child1:

   [SOME_EVENT]: {
      // this will throw an js error
      const a = undefined;
      console.log(a.b);
  }
}
  1. And I can successfully subscribe the error by following the official doc

    error: (err) => {
         // can catch the error here
         console.error(err);
    
         // but this event will no longer be received by the child1 actor
        child1Actor.send({ type: 'SOME_EVNET2' })
    }
    })
  2. But the strange thing is the child1 actor seems has crashed and no longer be able to receive any events.

I don't know if it is a reasonable behavior as I haven't found related description in official docs about the behavior of an actor after throwing js error. But my understanding is: since I catch the error, the actor should still be working.

Expected result

Expected the child1 actor can still be alive and able to receive events normally even after throwing an js error

Actual result

the child1 actor seems has crashed and no longer be able to receive any events.

Reproduction

https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vanilla-ts

Additional context

No response