Skip to content

async preValidation with custom validator does not trigger error handler #6214

@jakedipity

Description

@jakedipity

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.4.0

Plugin version

No response

Node.js version

22.11.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

15.5

Description

Errors thrown from a custom validator while using an async preValidation hook are not caught by the error handler. Instead the error is unhandled and propagated to the Node runtime which kills the app. Removing the hook all together or using a synchronous approach (with done()) resolves the issue.

This issue seems similar to #2707

Link to code that reproduces the bug

https://github.com/jakedipity/scratchspace/tree/main/fastify-bug

Expected Behavior

Error handler should be called (we should see a setErrorHandler <Error> logged), the client is given a response, and the instance continues running. Instead the handler is not called, the connection socket hangs up, and the instance crashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions