Skip to content

[Bug] Node middleware calls next() twice when req.on is missing #632

Closed

Description

@cursor

Problem

In packages/telemetry-node/src/index.ts, if req.on is missing, the else branch calls next() then done(), then execution falls through to another next().

Proposed change

Call next() once on all paths, and add coverage so it cannot regress.

Why this matters

Generic middleware is the Node integration story. Double next() breaks adapters.

Suggested implementation

  • packages/telemetry-node/src/index.ts

Keep this issue focused on the bug fix. Package-level Vitest setup is tracked separately.

Acceptance criteria

  • next is invoked once
  • $request is still recorded
  • Tests added/updated where applicable
  • Documentation updated where applicable

Contributor notes

This should be a good first contribution and does not require deep knowledge of the Telemetry Tracker architecture.

Open PRs against develop. See CONTRIBUTING.md.

Activity

  1. unjica commented on Sep 26, 2026

    @unjica
    Collaborator

    Reproduced on published [email protected] with Fastify 5.12.5 onRequest hook (request has no .on): done called 2×, route handler executed twice for 4 of 5 routes on Node 20/22/24; duration_ms 0–1 ms. See #720.

  2. unjica commented on Oct 16, 2026

    @unjica
    Collaborator

    Fixed: the middleware now calls next() exactly once on every path and records $request after it when there's no response emitter (commit 0cea057, shipped in @telemetry-tracker/node 1.4.0 on npm). Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions