-
Notifications
You must be signed in to change notification settings - Fork 702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[miniflare] fix: ensure Mutex
doesn't report itself as drained if locked
#4321
Conversation
🦋 Changeset detectedLatest commit: 9ce910c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6731655979/npm-package-wrangler-4321 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6731655979/npm-package-wrangler-4321 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6731655979/npm-package-wrangler-4321 dev path/to/script.js Additional artifacts:npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6731655979/npm-package-miniflare-4321 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/6731655979/npm-package-cloudflare-pages-shared-4321 Note that these links will no longer work once the GitHub Actions artifact expires.
| Please ensure constraints are pinned, and |
Previously, magic proxies were only poisoned once the runtime had restarted. This meant it was possible for heap objects to be freed while they were still in use, e.g. 1. `const caches = await Miniflare#getCaches()` _(create proxy)_ 2. `await caches.default.put(...)` _(resolve `put()` function)_ 3. `void Miniflare#setOptions()` _(in background)_ 4. Either... a. `caches` proxy GCed, `FinalizationRegistry` callback called, not yet poisoned, so calls `dispatchFetch()`, but `dispatchFetch()` blocked until `setOptions()` completes b. `caches.default.put(...)`, calls `dispatchFetch()`, but `dispatchFetch()` blocked until `setOptions()` completes 5. `setOptions()` completes, poisoning proxies, but too late 6. `dispatchFetch()` unblocked, sends request to incorrect DO The "blocked until `setOptions()` completes" step was fixed by the previous commit, hence we're only seeing this bug now. This change ensures we poison proxies synchronously as soon as `setOptions()` is called, ensuring the problematic `dispatchFetch()` calls never happen.
This test failures from this fix exposed another race condition. 😃 See the description of 9ce910c for details. Another potential fix I considered to eliminate this class of "request-sent-to-incorrect-Durable-Object-bug" was to add an |
Codecov Report
@@ Coverage Diff @@
## main #4321 +/- ##
==========================================
+ Coverage 75.34% 75.38% +0.04%
==========================================
Files 223 223
Lines 12341 12341
Branches 3190 3190
==========================================
+ Hits 9298 9303 +5
+ Misses 3043 3038 -5 |
What this PR solves / how to test:
Previously, Miniflare's
Mutex
implementation would report itself as drained if there were no waiters, regardless of the locked state. This bug meant that if you called but didn'tawait
Miniflare#setOptions()
, future calls toMiniflare#dispatchFetch()
(or any other asynchronousMiniflare
method) wouldn't wait for the options update to apply and the runtime to restart before sending requests. This change ensures we wait until the mutex is unlocked before reporting it as drained.Author has addressed the following:
Note for PR author:
We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label
highlight pr review
so future reviewers can take inspiration and learn from it.