Skip to content

Fix FiberHandle.clear race#6552

Merged
tim-smart merged 1 commit into
Effect-TS:mainfrom
xianjianlf2:fix/fiberhandle-clear-race-5906
Jul 23, 2026
Merged

Fix FiberHandle.clear race#6552
tim-smart merged 1 commit into
Effect-TS:mainfrom
xianjianlf2:fix/fiberhandle-clear-race-5906

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • capture the fiber being cleared before interrupting it
  • only empty the handle if it still points at that same fiber after interruption completes
  • add a regression test for installing a newer fiber while clear is waiting for the previous fiber to interrupt

Fixes #5906.

Tests

  • pnpm lint-fix
  • pnpm test packages/effect/test/FiberHandle.test.ts
  • pnpm check

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a race condition where clearing a fiber handle could inadvertently remove a newer fiber installed during the interruption process.
    • Fiber handles now preserve newly installed fibers correctly when clearing a previous fiber.
  • Tests

    • Added coverage to verify fiber handles retain newer fibers during concurrent interruption and replacement.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 23, 2026
@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 07bcba2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 110015c9-b775-41e1-bcbd-4eae1da830a1

📥 Commits

Reviewing files that changed from the base of the PR and between 4e0be58 and 07bcba2.

📒 Files selected for processing (3)
  • .changeset/fix-fiberhandle-clear-race.md
  • packages/effect/src/FiberHandle.ts
  • packages/effect/test/FiberHandle.test.ts

📝 Walkthrough

Walkthrough

FiberHandle.clear now avoids removing a newer fiber installed during interruption of the previous fiber. A deterministic test covers the race, and a patch changeset documents the fix.

Changes

FiberHandle clear race

Layer / File(s) Summary
Guard FiberHandle.clear cleanup
packages/effect/src/FiberHandle.ts, packages/effect/test/FiberHandle.test.ts, .changeset/fix-fiberhandle-clear-race.md
clear captures the interrupted fiber and conditionally clears only that fiber; a controlled-clock test verifies replacement preservation, and a patch changeset records the fix.

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

Suggested labels: bug

Suggested reviewers: gcanti

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The fix matches #5906 by preserving the current fiber and only clearing when the same fiber is still stored.
Out of Scope Changes check ✅ Passed All changes are directly related to the FiberHandle.clear race fix, its regression test, and the release note.

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

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 23, 2026
@IMax153 IMax153 added the 4.0 label Jul 23, 2026
@IMax153
IMax153 requested a review from tim-smart July 23, 2026 10:25
@tim-smart
tim-smart enabled auto-merge (squash) July 23, 2026 21:23
@tim-smart
tim-smart merged commit 0e0c9d7 into Effect-TS:main Jul 23, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.66 KB 6.64 KB +0.02 KB (+0.24%)
batching.ts 9.35 KB 9.33 KB +0.01 KB (+0.16%)
brand.ts 6.14 KB 6.20 KB -0.06 KB (-0.89%)
cache.ts 10.15 KB 10.13 KB +0.02 KB (+0.21%)
config.ts 18.98 KB 19.02 KB -0.04 KB (-0.19%)
differ.ts 17.20 KB 18.39 KB -1.19 KB (-6.48%)
http-client.ts 20.66 KB 20.65 KB +0.01 KB (+0.04%)
logger.ts 10.26 KB 10.24 KB +0.02 KB (+0.17%)
metric.ts 8.53 KB 8.52 KB +0.01 KB (+0.12%)
optic.ts 7.35 KB 7.35 KB 0.00 KB (0.00%)
pubsub.ts 14.18 KB 14.17 KB +0.01 KB (+0.06%)
queue.ts 11.11 KB 11.10 KB +0.01 KB (+0.07%)
schedule.ts 10.30 KB 10.28 KB +0.02 KB (+0.20%)
schema-class.ts 18.04 KB 18.12 KB -0.08 KB (-0.44%)
schema-fromJsonSchemaDocument.ts 4.06 KB 27.27 KB -23.20 KB (-85.10%)
schema-representation-roundtrip.ts 27.41 KB 24.12 KB +3.28 KB (+13.61%)
schema-string-transformation.ts 12.62 KB 12.59 KB +0.03 KB (+0.25%)
schema-string.ts 10.29 KB 10.26 KB +0.04 KB (+0.39%)
schema-template-literal.ts 14.35 KB 14.31 KB +0.04 KB (+0.27%)
schema-toArbitraryLazy.ts 20.85 KB 20.89 KB -0.04 KB (-0.21%)
schema-toCodeDocument.ts 21.41 KB 23.37 KB -1.96 KB (-8.40%)
schema-toCodecJson.ts 18.01 KB 18.28 KB -0.27 KB (-1.45%)
schema-toEquivalence.ts 17.91 KB 17.96 KB -0.05 KB (-0.30%)
schema-toFormatter.ts 17.73 KB 17.82 KB -0.08 KB (-0.47%)
schema-toJsonSchemaDocument.ts 20.31 KB 21.46 KB -1.16 KB (-5.38%)
schema-toRepresentation.ts 18.29 KB 18.51 KB -0.22 KB (-1.20%)
schema.ts 17.31 KB 17.38 KB -0.07 KB (-0.40%)
stm.ts 12.03 KB 12.02 KB +0.01 KB (+0.10%)
stream.ts 9.30 KB 9.28 KB +0.01 KB (+0.16%)

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

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

FiberHandle.clear looks racy ?

3 participants