inngest / inngest

A scalable, event-driven durable execution platform. Run stateful step functions functions deployed to serverless, servers, or the edge.
https://www.inngest.com/docs
Other
1.91k stars 71 forks source link

`step.waitForEvent` does not get resolved if events are issued in quick succession #1433

Open manan30 opened 3 months ago

manan30 commented 3 months ago

Describe the bug

Let's say I have eventA and eventB and eventB needs to wait for eventA to complete. Here is how both events are implemented

// eventA
createFunction(
  { id: 'event-A', name: 'EventA' },
  { event: 'eventA' },
  async ({ step, logger }) => {
    // eventA implementation
  })
})
// eventB
createFunction(
  { id: 'event-B', name: 'EventB' },
  { event: 'eventB' },
  async ({ step, logger }) => {

  const waitedEvent = await step.waitForEvent('event-A', {
    event: 'eventA',
    timeout: '1m',
    if: `async.data.key == "${event.data.key}"`
  });
  logger.info({ waitedEvent });

  // eventB implementation
})

Now the issue is if I do something like this, send both the events one after the other immediately

await inngestClient.send({name: "eventB"})
await inngestClient.send({name: "eventA"})

eventB never receives eventA and it always ends up timing out.

But if I add a small timeout between eventB and eventA, something like

await inngestClient.send({name: "eventB"})
await new Promise((resolve) => setTimeout(resolve, 5000))
await inngestClient.send({name: "eventA"})

then eventB does indeed wait for eventA.

I think this might be a race condition but I am not sure if that is intended behavior

Expected behavior

I was hoping the order in which events were issued was deterministic and would not run into race conditions

linear[bot] commented 3 months ago

INN-3158 `step.waitForEvent` does not get resolved if events are issued in quick succession

tonyhb commented 3 months ago

We have something coming for you in several weeks. Stay tuned :)

manan30 commented 3 months ago

We have something coming for you in several weeks. Stay tuned :)

Perfect, excited about it. Thank you!

ODreelist commented 1 day ago

Bumping. I am running into this issue myself, it works reliably in localdev but it just doesn't seem to catch in production. Any news or guidance on this issue would be greatly appreciated. We just started building with inngest and I would hate to have to work around this issue if we continue.