Skip to content

fix(wa-sqlite): make direct and dedicated teardown terminal - #229

Merged
Antonov548 merged 3 commits into
mainfrom
fix/wa-sqlite-terminal-teardown
Aug 4, 2026
Merged

fix(wa-sqlite): make direct and dedicated teardown terminal#229
Antonov548 merged 3 commits into
mainfrom
fix/wa-sqlite-terminal-teardown

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Mark direct clients closed before database cleanup can fail.
  • Always terminate a dedicated worker and remove its listeners when the init, close, or drop RPC rejects.
  • Preserve existing error behavior: close() is best-effort, drop() reports the first teardown error, and repeated teardown does not retry the backend.
  • Add focused regressions for failed direct close/drop and dedicated-worker init/close/drop.

Why

cybersemics/em#4325 uses persistent OPFS with dedicated-worker, plus direct for unit tests and some Puppeteer profiles. Its integration currently falls back from a rejected drop() to close() because wa-sqlite can leave the lower handle live after teardown fails.

em also treats initialization as retryable. If a dedicated worker rejects its init RPC, createTreecrdtClient() returns no client handle, so em cannot clean up the worker itself. Terminating that failed endpoint must therefore be guaranteed by wa-sqlite.

This extracts only the relevant single-client lifecycle slice from #208. It intentionally does not include #209 SharedWorker peer invalidation, protocol/server changes, cross-tab behavior, OPFS memory fallback, or a generic lifecycle-hook abstraction.

With this behavior, em can discard the terminal client after drop() settles, remove its drop()close() fallback, and safely retry after a dedicated-worker initialization rejection. em still owns WebSocket shutdown, materialization unsubscribe, provider reset, and lifecycle serialization.

Validation

  • focused single-client teardown suite — 5/5
  • wa-sqlite TypeScript build
  • Prettier and git diff --check
  • full CI build and test matrix

@marcus-pousette
marcus-pousette force-pushed the fix/wa-sqlite-terminal-teardown branch from bbf7da1 to 6afda30 Compare July 24, 2026 11:02
@marcus-pousette marcus-pousette changed the title fix(wa-sqlite): make client teardown terminal fix(wa-sqlite): make direct and dedicated teardown terminal Jul 24, 2026
@marcus-pousette
marcus-pousette force-pushed the fix/wa-sqlite-terminal-teardown branch from 078817d to 15cd2c5 Compare July 24, 2026 13:22
@Antonov548
Antonov548 merged commit 510954e into main Aug 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants