Skip to content

Commit

Permalink
Prevent ProxyServer Durable Object eviction
Browse files Browse the repository at this point in the history
cloudflare/workerd#1138 introduced Durable Object's eviction behaviour
to `workerd`. We really don't want the `ProxyServer`'s singleton
object to be evicted, as this would invalidate proxy stubs' heap
addresses. This change makes sure the `preventEviction` flag is set.
  • Loading branch information
mrbbot committed Oct 17, 2023
1 parent 505fd19 commit adf8ec8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/miniflare/src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ export function getGlobalServices({
{
className: "ProxyServer",
uniqueKey: `${SERVICE_ENTRY}-ProxyServer`,
// `ProxyServer` relies on a singleton object containing of "heap"
// mapping addresses to native references. If the singleton object
// were evicted, addresses would be invalidated. Therefore, we
// prevent eviction to ensure heap addresses stay valid for the
// lifetime of the `workerd` process
preventEviction: true,
},
],
// `ProxyServer` doesn't make use of Durable Object storage
Expand Down
7 changes: 0 additions & 7 deletions packages/miniflare/src/workers/core/proxy.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ function getType(value: unknown) {
// TODO(someday): extract `ProxyServer` into component that could be used by
// other (user) Durable Objects
export class ProxyServer implements DurableObject {
// On the first `fetch()`, start a `setInterval()` to keep this Durable Object
// and its heap alive. This is required to ensure heap references stay valid
// for the lifetime of this `workerd` process (except it isn't since `workerd`
// doesn't evict Durable Objects yet :P, but it probably will soon).
anchorInterval?: number;
nextHeapAddress = ProxyAddresses.USER_START;
readonly heap = new Map<number, unknown>();

Expand Down Expand Up @@ -116,8 +111,6 @@ export class ProxyServer implements DurableObject {
}

async fetch(request: Request) {
// Make sure this instance is kept alive
this.anchorInterval ??= setInterval(() => {}, 10_000);
try {
return await this.#fetch(request);
} catch (e) {
Expand Down

0 comments on commit adf8ec8

Please sign in to comment.