Skip to content
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

fix the need to await getServerByName #26

Open
threepointone opened this issue May 31, 2024 · 3 comments
Open

fix the need to await getServerByName #26

threepointone opened this issue May 31, 2024 · 3 comments

Comments

@threepointone
Copy link
Owner

This might be a bug in workerd, must follow up
https://github.com/threepointone/partyflare/blob/69c6c859223f7e419ac0b7a5f14331e44eeeb009/packages/partyflare/src/index.ts#L53-L57

@threepointone
Copy link
Owner Author

related cloudflare/workerd#2246

@threepointone threepointone pinned this issue Jun 10, 2024
@threepointone threepointone changed the title fix the need to await Party.withRoom fix the need to await getServerByName Jun 18, 2024
@threepointone
Copy link
Owner Author

this is now not as slow as it was, even tho it's async, which is good

@aroman
Copy link

aroman commented Sep 15, 2024

this is now not as slow as it was, even tho it's async, which is good

@threepointone stupid idea i'm sure you've already considered:

why not just include the name in every request (e.g. via a header like you're currently doing), and only initialize it if it's missing? seems a lot less finicky than needing to ensure a specific fetch request/RPC is made once but definitely before any subsequent requests. this is what we do and it works fine for us — actually, for us, we just use the DO worker as a complete pass-thru to the DO itself, so the DO can pull its own name directly out of the request URL.

here's our entire DO worker.ts:

import { getSantizedRoomIdFromGameServerUrl } from '@common/getSantizedRoomIdFromRequest';

const worker: ExportedHandler<Environment> = {
  async fetch(request, env) {
    const roomId = getSantizedRoomIdFromGameServerUrl(request.url);
    if (!roomId) {
      return new Response(`Nothing to see here. Move along.`, {
        status: 200,
      });
    }

    const durableObjectId = env.ROOM_DURABLE_OBJECT.idFromName(roomId);
    const durableObjectStub = env.ROOM_DURABLE_OBJECT.get(durableObjectId);
    try {
      return await durableObjectStub.fetch(request);
    } catch (error) {
      console.error('Failed to fetch from durable object', error);
      return new Response(`Something went wrong: ${error}`, {
        status: 500,
      });
    }
  },
};

export { RoomDurableObject } from './RoomDurableObject';
export default worker;

In the meantime... I eagerly await cloudflare/workerd#2240 being fixed :D

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

No branches or pull requests

2 participants