Skip to content

Fix two bugs affecting persistent stubs#6840

Merged
kentonv merged 2 commits into
mainfrom
kenton/persistent-fixes-github
Jun 22, 2026
Merged

Fix two bugs affecting persistent stubs#6840
kentonv merged 2 commits into
mainfrom
kenton/persistent-fixes-github

Conversation

@kentonv

@kentonv kentonv commented Jun 22, 2026

Copy link
Copy Markdown
Member

Would like to get this into a workerd release as it is blocking Gadgets local development.

kentonv added 2 commits June 22, 2026 13:47
When using persistent stubs, it turns out that a stub produced by `ctx.restore()` holds a self-reference which can lead to a cyclic self-cancellation issue when tearing down the IoContext. We were deferring destruction of the worker, but not unlink(). We need to defer both.
If any externals are present, clearExternalsIfPresent() will execute a new query which causes the previous `query.changeCount()` to return the wrong value, because the change count comes from a SQLite API that reports from whatever query ran last.

Arguably, the `changeCount()` method is a bad interface but I've left fixing it as a TODO.
@kentonv kentonv requested review from a team as code owners June 22, 2026 18:50
@ask-bonk

ask-bonk Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Good — clearExternalsIfPresent runs another SQL statement (line 187), which is precisely the problematic intervening query that corrupts changeCount(). The fix correctly captures changeCount() before the query object is destroyed and before clearExternalsIfPresent runs.

This is a clean, correct fix. Both bugs are legitimate and the fixes are well-structured. The code is correct and I don't see actionable issues.

LGTM

github run

@kentonv kentonv enabled auto-merge June 22, 2026 18:54
@kentonv kentonv disabled auto-merge June 22, 2026 19:05
@kentonv kentonv merged commit f10aeba into main Jun 22, 2026
23 of 24 checks passed
@kentonv kentonv deleted the kenton/persistent-fixes-github branch June 22, 2026 19:09
@codspeed-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 12.18%

❌ 1 regressed benchmark
✅ 71 untouched benchmarks
⏩ 129 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
Encode_ASCII_32[TextEncoder][0/0/32] 2.8 ms 3.2 ms -12.18%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing kenton/persistent-fixes-github (5422453) with main (682dad1)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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.

3 participants