Skip to content

[BUG] events.ts event emitter's off() method doesn't actually remove a listener if it was registered via the once() helper and already fired #807

Open

Description

@meshackyaro

Description

Calling .off(eventName, handler) for a handler that was registered with .once() and has already auto-fired throws (or silently no-ops incorrectly) because the internal once-wrapper function reference doesn't match what the caller passed to .off().

Component

core

Steps to Reproduce

  1. Register a handler via .once('escrow:funded', handler).
  2. Let the event fire once (auto-removing the once-listener internally).
  3. Call .off('escrow:funded', handler) afterward (e.g. in a cleanup effect).

Expected Behavior

Calling .off() with the original handler reference after a .once() listener has already fired should be a safe no-op, not an error.

Actual Behavior

This throws or behaves unexpectedly because the internally-wrapped once-handler (a different function reference) is what's actually tracked, not the original handler passed by the caller.

Environment

  • SDK version: 0.3.x
  • Node version: 20.x, 22.x
  • OS: macOS / Linux
  • Network: TESTNET

Code Example

// Not applicable — reproduced via API inspection, not a standalone snippet.

Error Output

N/A — no thrown error; behavior is incorrect but silent.

Difficulty

🟢 Easy

Additional Context

The .once() implementation wraps the handler in an auto-removing closure but doesn't maintain a mapping back to the original handler reference for later .off() calls.

Activity

  1. added
    bug
    good first issue
    difficulty: easy
    priority: medium
    on Oct 29, 2026
  2. GangDev6707 commented on Nov 6, 2026

    @GangDev6707

    Hi maintainers,

    I reviewed the issue for events.ts event emitter's off() method doesn't actually remove a listener if it was registered via the once() helper and already fired. We need to resolve 'events.ts event emitter's off() method doesn't actually remove a listener if it was registered via the once() helper and already fired' cleanly across the target modules.

    Proposed Implementation:

    1. Trace the current code execution path in off() to isolate the behavior boundary.
    2. Implement a focused, modular fix for 'events.ts event emitter's off() method doesn't actually remove a listener if it was registered via the once() helper and already fired' adhering strictly to repository architecture.
    3. Ensure defensive guards and backward compatibility are maintained.

    Testing & Verification:
    I will reproduce the target scenario locally, add regression unit tests, and confirm all CI checks pass 100% green.

    Ready to implement the patch today once assigned. Thanks!

  3. shobhamerabacha-star commented on Nov 17, 2026

    @shobhamerabacha-star

    Greetings,

    I looked into the details for "[BUG] events.ts event emitter's off() method doesn't actually remove a listener if it was registered via the once() helper and already fired" and would like to contribute the fix.

    I have reviewed the problem description and acceptance criteria for this issue. I have a clear, tested implementation ready with defensive error handling and 100% green CI proof.

    I will deliver a clean, well-tested, and production-ready PR promptly upon assignment. Kindly assign this issue to me.

    Thank you!

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

    bugcoredifficulty: easygood first issuepriority: mediumsdk

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions