dotansimha / graphql-yoga

🧘 Rewrite of a fully-featured GraphQL Server with focus on easy setup, performance & great developer experience. The core of Yoga implements WHATWG Fetch API and can run/deploy on any JS environment.
https://the-guild.dev/graphql/yoga-server
MIT License
8.22k stars 567 forks source link

Error when aborting subscription with µWebSockets.js #3246

Closed etienneo closed 5 months ago

etienneo commented 5 months ago

Describe the bug

When using subscriptions with µWebSockets.js, every time a subscription is aborted by the client, I get the following error log:

Unexpected error while handling request: 
Error: uWS.HttpResponse must not be accessed after uWS.HttpResponse.onAborted callback, or after a successful response. See documentation for uWS.HttpResponse and consult the user manual.
    at forwardResponseBodyToUWSResponse (***/node_modules/@whatwg-node/server/cjs/uwebsockets.js:47:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

The problem does not happen when the query is sent as a get parameter, only when the query is sent as post data.

Your Example Website or App

CodeSandbox

Steps to Reproduce the Bug or Issue

From the minimal example attached, doing the following curl and interrupting it will show the error message:

curl --location 'http://0.0.0.0:4000/graphql' \
--header 'Content-Type: application/json' \
--data '{"query":"subscription MySubscription {\n  countdown(from: 10)\n}"}'

With the query as get data (or with the graphiql interface that sends the query as get), the problem won't happen

curl 'http://0.0.0.0:4000/graphql?query=subscription+MySubscription%7Bcountdown%28from%3A10%29%7D&operationName=MySubscription&extensions=%7B%7D' \
--header 'Content-Type: application/json'

Expected behavior

These errors, although they don't really impact the client are making it hard to monitor errors server side.

Screenshots or Videos

No response

Platform

Additional context

Thanks a lot for your help

ardatan commented 5 months ago

Could you update @whatwg-node/node-fetch and @whatwg-node/server packages in your lockfile and try again? You can find the versions here; https://github.com/ardatan/whatwg-node/releases/tag/release-1714134977033

etienneo commented 5 months ago

Thanks a lot @ardatan, that works perfectly for me now :)