Skip to content

fix(synology-chat,twitch,zalouser): clear timeout timers in Promise.race patterns - #39745

Closed
Bortlesboat wants to merge 1 commit into
openclaw:mainfrom
Bortlesboat:fix/extension-timer-leaks
Closed

Bortlesboat wants to merge 1 commit into
openclaw:mainfrom
Bortlesboat:fix/extension-timer-leaks

Conversation

@Bortlesboat

Copy link
Copy Markdown
Contributor

Summary

Several extensions use Promise.race with setTimeout-based timeouts but never clear the timer when the main promise wins the race. When the winning promise resolves/rejects first, the losing setTimeout fires later — either rejecting an unlistened promise (causing unhandledRejection) or keeping a timer handle alive unnecessarily.

Affected extensions:

  • synology-chat webhook-handler.ts: 120s agent response timeout rejects after nobody is listening
  • twitch probe.ts: connection timeout rejects after successful connect
  • zalouser probe.ts: timeout timer keeps running after user info resolves

This is the same class of bug fixed in the Nostr extension (#39742) — systematic audit found these additional instances.

Changes

Store timer handles and clear them in finally blocks so timers are always cleaned up regardless of which side wins the race.

Test plan

  • npx vitest run extensions/synology-chat/ — all tests pass
  • npx vitest run extensions/twitch/ — all tests pass
  • npx vitest run extensions/zalouser/ — all tests pass
  • 309 total tests, 0 failures
  • No functional behavior change — only timer cleanup added

…ace patterns

Several extensions use Promise.race with setTimeout-based timeouts but
never clear the timer when the main promise wins the race:

- synology-chat webhook-handler: 120s agent response timeout rejects
  after nobody is listening, causing an unhandled promise rejection
- twitch probe: connection timeout rejects after successful connect
- zalouser probe: timeout timer keeps running after user info resolves

Store timer handles and clear them in finally blocks so timers are
always cleaned up regardless of which side wins the race.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added channel: zalouser Channel integration: zalouser channel: twitch Channel integration: twitch size: S labels Mar 8, 2026
@greptile-apps

greptile-apps Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a recurring resource-leak pattern across three extensions where Promise.race timeout promises were created but their setTimeout handles were never cleared when the other promise won the race. The fix is mechanical and correct: store the timer handle in a let variable (assigned synchronously inside the Promise constructor, so always defined before await settles), then call clearTimeout in a finally block.

Changes per file:

  • extensions/synology-chat/src/webhook-handler.ts: The 120s agent-response timeout would previously reject into an unlistened promise, causing an unhandledRejection event every time a message was successfully delivered within the limit. Fixed by wrapping the Promise.race + send-message logic in try/finally and clearing the timer on exit.
  • extensions/twitch/src/probe.ts: The connection-timeout timer kept running after a successful connect, unnecessarily holding a timer handle until it fired. Fixed with the same pattern inside the existing try/catch.
  • extensions/zalouser/src/probe.ts: The timeout timer in the optional-timeout branch was never cleared. The ternary was refactored into an if/else with try/finally to allow the clearTimeout call, with no change in observable behaviour.

All three fixes are correct — timer is assigned synchronously in the Promise constructor before the outer await is reached, so clearTimeout(timer) in finally is always safe. Error propagation paths are unchanged.

Confidence Score: 5/5

  • This PR is safe to merge — changes are minimal, purely additive timer cleanup, with no logic or behaviour changes.
  • The diff is small and mechanical: three identical let timer + clearTimeout in finally patterns applied consistently. All timer assignments are synchronous, all finally blocks are correctly scoped, and existing error-propagation paths are preserved. No new code paths are introduced.
  • No files require special attention.

Last reviewed commit: cf4d265

@druide67

Copy link
Copy Markdown
Contributor

This looks good. The cleanup timer approach is cleaner than removing the timeout entirely, and covering all 3 extensions in one PR makes sense.

@Bortlesboat

Copy link
Copy Markdown
Contributor Author

Thanks for the review @druide67 — glad the cleanup timer approach reads well. Is this ready to merge from the maintainer side, or is there anything else needed before it lands?

@Bortlesboat

Copy link
Copy Markdown
Contributor Author

Trimmed my open PR queue from 10 → 7 to make review easier. This one has green CI across all checks and a positive review from @druide67 — happy to address any remaining feedback if needed.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 24, 2026
@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open. This PR still has useful timer-cleanup work for Zalouser and possibly Synology Chat, but it is not merge-ready because current main already has the Twitch cleanup, the branch is conflicting, real behavior proof is missing, and the Synology hunk overlaps the open configured-timeout issue at #59966.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes, by source inspection rather than a live run. Current main still leaves Synology Chat and Zalouser timeout timers unretained and uncleared when the main operation wins, while Twitch already clears its timeout handle.

Is this the best way to solve the issue?

No, not in the current branch form. The cleanup pattern is useful, but the PR should be rebased, drop the obsolete Twitch hunk, and coordinate the Synology hunk with the configured-timeout bug before merge.

Security review:

Security review cleared: The diff only changes bundled plugin TypeScript timer cleanup and does not modify dependencies, workflows, scripts, secrets, permissions, generated files, or package metadata.

What I checked:

  • stale F-rated PR: PR was opened 2026-03-08T10:57:56Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • druide67: PR metadata for feat(channels): add Synology Chat native channel #23012 identifies this handle as the Synology Chat channel author, and commit 03586e3 added the webhook handler containing the 120-second race; the same handle reviewed this PR positively and opened the earlier Synology timeout-removal PR. (role: introduced Synology Chat behavior and prior related contributor; confidence: high; commits: 03586e3d0057; files: extensions/synology-chat/src/webhook-handler.ts, extensions/synology-chat/src/webhook-handler.test.ts)
  • steipete: Commit af954a8 added the current-main Twitch timeout cleanup, and commit f067ea2 added the current Zalouser probe surface being discussed here. (role: recent area contributor; confidence: high; commits: af954a81d13e, f067ea25b420; files: extensions/twitch/src/probe.ts, extensions/zalouser/src/probe.ts)
  • jaydenfyi: The merged Twitch plugin PR introduced the Twitch probe file that current main later updated with timer cleanup. (role: introduced Twitch plugin path; confidence: medium; commits: f5c90f0e5c7a; files: extensions/twitch/src/probe.ts, extensions/twitch/src/probe.test.ts)
  • suminhthanh: Related PR metadata shows this handle proposed Zalouser channel probing and status wiring before the current-main probe was added through later history. (role: Zalouser feature-history contributor; confidence: low; files: extensions/zalouser/src/probe.ts, extensions/zalouser/src/channel.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against a4a1abbe3097.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 26, 2026
@clawsweeper clawsweeper Bot added the P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. label May 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 16, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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

Labels

channel: twitch Channel integration: twitch channel: zalouser Channel integration: zalouser merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants