Skip to content

Fix cancel heartbeat delay timer on abort - #527

Merged
parfeon merged 3 commits into
masterfrom
CLEN-3884-fix-timer-termination
Oct 14, 2026
Merged

parfeon merged 3 commits into
masterfrom
CLEN-3884-fix-timer-termination

Conversation

@parfeon

@parfeon parfeon commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

fix(presence): cancel heartbeat delay timer on abort

Clear pending heartbeat delay timer when presence effect is aborted, so destroy no longer waits for the full heartbeat interval.

refactor(presence): remove unused delay dependency

Drop delay from event engine dependencies and client setup, as heartbeat delay now uses heartbeatDelay.

test(presence): cover heartbeat delay cancellation

Add tests for timer cancel on destroy, no heartbeats after destroy and heartbeat loop stop on zero interval.

Clear pending heartbeat delay timer when presence effect is aborted, so destroy no longer waits for
the full heartbeat interval.

refactor(presence): remove unused `delay` dependency

Drop `delay` from event engine dependencies and client setup, as heartbeat delay now uses
`heartbeatDelay`.

test(presence): cover heartbeat delay cancellation

Add tests for timer cancel on destroy, no heartbeats after destroy and heartbeat loop stop on zero
interval.
@parfeon parfeon self-assigned this Oct 13, 2026
@parfeon
parfeon requested a review from mohitpubnub as a code owner October 13, 2026 22:48
@parfeon parfeon added the status: done This issue is considered resolved. label Oct 13, 2026
@parfeon
parfeon requested a review from jguz-pubnub as a code owner October 13, 2026 22:48
@parfeon parfeon added priority: high This PR should be reviewed ASAP. type: fix This PR contains fixes to existing features. labels Oct 13, 2026
@pubnub-snyk-universal-prd

pubnub-snyk-universal-prd Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1efe7925-32aa-4303-8039-06c58ccf2c8a
📥 Commits

Reviewing files that changed from the base of the PR and between 21405e1 and 3e7adb8.

⛔ Files ignored due to path filters: 2
  • dist/web/pubnub.js is excluded by !**/dist/**
  • dist/web/pubnub.min.js is excluded by !**/dist/**, !**/*.min.js
📒 Files selected for processing: 6
  • .pubnub.yml
  • CHANGELOG.md
  • README.md
  • lib/core/components/configuration.js
  • package.json
  • src/core/components/configuration.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The presence heartbeat delay now supports cancellation. The presence wait effect cancels the delay when aborted. Tests cover timer cancellation, heartbeat behavior after destroy, and resetting the heartbeat interval to zero. Release metadata and links now identify version 13.1.2.

Changes: Presence heartbeat cancellation and release

Layer / File(s) Summary
Cancellable presence wait
src/event-engine/presence/dispatcher.ts, src/core/pubnub-common.ts, src/event-engine/dispatcher.ts, lib/event-engine/presence/dispatcher.js, lib/core/pubnub-common.js, test/unit/event_engine_presence.test.ts, CHANGELOG.md, .pubnub.yml
The heartbeat delay returns a promise and a cancellation function. The wait effect cancels the delay on abort. Tests check timer cancellation and heartbeat behavior after destroy or an interval reset. The generic delay dependency was removed. The changelog records these changes.
Version 13.1.2 release metadata
package.json, src/core/components/configuration.ts, lib/core/components/configuration.js, README.md, .pubnub.yml
The package and configuration report version 13.1.2. The README CDN links and release artifact URLs point to version 13.1.2.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant PresenceDispatcher
  participant PubNubCore
  participant AbortSignal
  participant HeartbeatTimer
  PresenceDispatcher->>PubNubCore: Call heartbeatDelay()
  PubNubCore-->>PresenceDispatcher: Return promise and cancelDelay
  PresenceDispatcher->>AbortSignal: Subscribe cancelDelay to abort
  AbortSignal->>PresenceDispatcher: Emit abort
  PresenceDispatcher->>PubNubCore: Call cancelDelay()
  PubNubCore->>HeartbeatTimer: Clear scheduled timeout
  PubNubCore-->>PresenceDispatcher: Reject promise with cancellation error
Loading
Merge Risk: ⚪ Minimal · up to 3e7ad

No actionable merge-blocking issue remains: destroying the client cancels the pending heartbeat, and the release metadata consistently identifies version 13.1.2.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: cancelling the heartbeat delay timer when the presence effect is aborted.
Description check Passed The description directly matches the changeset. It covers heartbeat timer cancellation, removal of the unused delay dependency, and related tests.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 7…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

package.json

Oops! Something went wrong! :(

ESLint: 8.57.1

ReferenceError: convertToJson is not defined
at Object._r [as parseSourceFile] (file:///node_modules/prettier/plugins/typescript.mjs:14:125346)
at dh (file:///node_modules/prettier/plugins/typescript.mjs:14:123961)
at Kh (file:///node_modules/prettier/plugins/typescript.mjs:17:66667)
at a4 (file:///node_modules/prettier/plugins/typescript.mjs:17:70400)
at l0 (file:///node_modules/prettier/plugins/typescript.mjs:17:70169)
at file:///node_modules/prettier/plugins/typescript.mjs:20:1441
at s4 (file:///node_modules/prettier/plugins/typescript.mjs:17:70720)
at Object.M4 [as parse] (file:///node_modules/prettier/plugins/typescript.mjs:20:1425)
at parse5 (file:///node_modules/prettier/index.mjs:19983:24)
at async coreFormat (file:///node_modules/prettier/index.mjs:20531:25)

src/core/components/configuration.ts

ESLint skipped: the matched ESLint configuration already failed (unknown).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Remove `abortSignal` listener created for `wait` effect once heartbeat delay resolves.

@mohitpubnub mohitpubnub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@parfeon

parfeon commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@pubnub-release-bot release

@parfeon
parfeon merged commit 3655397 into master Oct 14, 2026
10 checks passed
@parfeon
parfeon deleted the CLEN-3884-fix-timer-termination branch October 14, 2026 07:41
@pubnub-release-bot

Copy link
Copy Markdown
Contributor

🚀 Release successfully completed 🚀

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

Labels

priority: high This PR should be reviewed ASAP. status: done This issue is considered resolved. type: fix This PR contains fixes to existing features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants