-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[miniflare] fix: ensure
Mutex
doesn't report itself as drained if l…
…ocked (#4321) * fix: ensure `Mutex` doesn't report itself as drained if locked * fix: ensure proxies poisoned synchronously 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.
- Loading branch information
Showing
5 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"miniflare": patch | ||
--- | ||
|
||
fix: ensure `Mutex` doesn't report itself as drained if locked | ||
|
||
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't `await` `Miniflare#setOptions()`, future calls to | ||
`Miniflare#dispatchFetch()` (or any other asynchronous `Miniflare` 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters