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

Function stuck when step.run fails after a step.waitForEvent #1290

Open
danielamezcua opened this issue Apr 18, 2024 · 1 comment
Open

Function stuck when step.run fails after a step.waitForEvent #1290

danielamezcua opened this issue Apr 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@danielamezcua
Copy link

Describe the bug
When a function configured with retries set to 0 waits for an event and then encounters an error in a subsequent step, it gets stuck instead of terminating or failing gracefully.

To Reproduce

import { z } from 'zod'

import { serve } from 'inngest/next'
import { EventSchemas, Inngest, LiteralZodEventSchema } from 'inngest'

const triggerEvent = z.object({
  name: z.literal('trigger.event'),
  data: z.object({}),
}) satisfies LiteralZodEventSchema

const waitEvent = z.object({
  name: z.literal('wait.event'),
  data: z.object({}),
}) satisfies LiteralZodEventSchema

const inngest = new Inngest({
  id: 'test',
  schemas: new EventSchemas().fromZod([triggerEvent, waitEvent]),
})

const testFunction = inngest.createFunction(
  {
    id: 'test-stuck-function',
    retries: 0,
  },
  { event: 'trigger.event' },
  async ({ event, step }) => {
    const received = await step.waitForEvent('wait-for-event', {
      event: 'wait.event',
      timeout: '15m',
    })

    if (!received) return

    await step.run('issue-step', async () => {
      throw new Error()
    })
    return
  }
)

export default serve({
  client: inngest,
  functions: [testFunction],
})

Expected behavior
The function should terminate or fail immediately after the step that throws an error, given that retries is set to 0. The step should not be scheduled for being retried. The function should not get stuck in a pending or executing state.

Screenshots / Stack trace dump
image

System info
Happens both on inngest cloud and

  • inngest-cli version: 0.27.0-c302c5c7
  • nextjs version: 13.1.6
  • node runtime:

Additional context
Interestingly if I wrap my steps in try catch blocks and then rethrow the error as a NonRetriableError, the function will terminate gracefully.

@danielamezcua danielamezcua added the bug Something isn't working label Apr 18, 2024
Copy link

linear bot commented Apr 18, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants