Skip to content

events: on() leaves emitter paused after return() #67917

Backlog

Description

@outslept

Version

v26.13.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

events

What steps will reproduce the bug?

import { on } from 'node:events';
import { PassThrough } from 'node:stream';

const stream = new PassThrough();
const it = on(stream, 'data', { highWaterMark: 1 });

stream.write('a');
stream.write('b');

await it.return();

console.log(stream.isPaused());

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

prints false. сalling return stops listening to stream and should resume it if on paused it

What do you see instead?

prints true

Additional information

No response

Activity

  1. bunnysayzz commented on Dec 1, 2026

    @bunnysayzz
    Contributor

    Traced this to closeHandler in lib/events.js. When the buffer fills past highWatermark, eventHandler pauses the emitter, and the only resume path is in next() when the buffer drains below lowWatermark. closeHandler just clears the local paused flag, so after return() the emitter stays paused for good and nothing ever resumes it.

    Fix is in closeHandler: if paused, call emitter.resume() before clearing the flag, same guard next() already uses. Adding a regression test in test-events-on-async-iterator.js that checks isPaused() is false after return() with a filled buffer.

    PR: #67942

  2. added
    events
    on Dec 1, 2026
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

    events

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions