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

The error The script will never generate a response on Cloudflare Workers. #4201

Closed
4 tasks
aiji42 opened this issue Jul 27, 2022 · 6 comments
Closed
4 tasks

Comments

@aiji42
Copy link

aiji42 commented Jul 27, 2022

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

I have deployed and running graphql-mesh on Cloudflare Workers.
When accesses increase, the status 500 error The script will never generate a response is returned at a high frequency.

After investigating the cause, I found it mentioned here that storing a Promise in a global level variable and using it causes the error. This is due to the fact that the Cloudflare Workers runtime is V8 isolate.

Eventually I came to the conclusion that the script (.mesh/index.ts) generated by the mesh build was the cause.

let meshInstance$: Promise<MeshInstance<MeshContext>>;
// ^^^^^^
export function getBuiltMesh(): Promise<MeshInstance<MeshContext>> {
  if (meshInstance$ == null) {
    meshInstance$ = getMeshOptions().then(meshOptions => getMesh<MeshContext>(meshOptions)).then(mesh => {
      const id$ = mesh.pubsub.subscribe('destroy', () => {
        meshInstance$ = undefined;
        id$.then(id => mesh.pubsub.unsubscribe(id)).catch(err => console.error(err));
      });
      return mesh;
    });
  }
  return meshInstance$;
}

My Worker code is as follows.

import { getBuiltMesh } from "../.mesh";
import { createServer } from "@graphql-yoga/common";
import { useDisableIntrospection } from "@envelop/disable-introspection";

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    const mesh = await getBuiltMesh();
    const server = createServer({
      plugins: mesh.plugins,
      graphiql: {
        endpoint: "/graphql",
      }
    });

    return server.fetch(request);
  },
};

To Reproduce
Steps to reproduce the behavior:

  1. Generate .mesh by mesh build.
  2. Deploy the above code to Cloudflare Wokers.
  3. Access a large amount of data using benchmark tools.

Expected behavior

Expect to be able to access it without error.

Environment:

  • @graphql-mesh/cli: 0.75.3
  • @graphql-mesh/graphql: 0.29.5
  • @graphql-mesh/transform-naming-convention: 0.10.61
  • @graphql-mesh/transform-prefix: 0.11.60
  • @graphql-yoga/common: 2.12.3
  • graphql: 16.5.0
  • Runtime: Cloudflare Workers

Additional context

Using DO (Durable Objects) would have solved the problem, but I would like to know if there is a way to get it running stably without using DO.

@samdenty
Copy link

samdenty commented Jan 7, 2023

I've ran into this and am tracking it here cloudflare/workers-rs#255

@ardatan
Copy link
Owner

ardatan commented Jan 7, 2023

@samdenty
Copy link

samdenty commented Jan 7, 2023

oh this isn't wasm, nvm then!

@ardatan ardatan closed this as completed Jan 18, 2023
@ardatan
Copy link
Owner

ardatan commented Jan 18, 2023

Just checking @samdenty . Your issue has been fixed right?

@alibombaye
Copy link

Hello, I'm seeing the same error when running a mesh gateway hosted on cloudflare. We are currently running some load tests to see if it is fit for purpose and occasionally see the same error as mentioned above.

@ardatan I have followed the same as the example and I still get the same.

@ardatan
Copy link
Owner

ardatan commented Feb 6, 2023

Could you create a new issue with a reproduction? Thanks!

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

4 participants