nodejs / undici

An HTTP/1.1 client, written from scratch for Node.js
https://nodejs.github.io/undici
MIT License
6.24k stars 542 forks source link

Undici throws a terminated error #1490

Closed Eddy84 closed 2 years ago

Eddy84 commented 2 years ago

Bug Description

I have a bug with graphl-codegen which is very likely caused by undici closing the connection and sending a terminated signal?

I have double checked my backend with various graphql clients and plain http requests doing the introspection query, the bug is definitely in undici.

The server receives the request, but it is terminated.

A stacktrace is included below:

Here is the related issue https://github.com/dotansimha/graphql-code-generator/issues/7934

Reproducible By

See the linked issue above

Expected Behavior

Return a response

Logs & Screenshots

See below

Environment

Additional context

Stacktrace:

` Exited with an error DetailedError: Failed to load schema
    at loadSchema (/home/eduard/Projects/ecommerce/frontend/node_modules/@graphql-codegen/cli/bin.js:504:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /home/eduard/Projects/ecommerce/frontend/node_modules/@graphql-codegen/cli/bin.js:1034:65 {
  details: '\n' +
    '        Failed to load schema from http://localhost/service:\n' +
    '\n' +
    '        terminated\n' +
    '        TypeError: terminated\n' +
    '    at Fetch.onAborted (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:1893:49)\n' +
    '    at Fetch.emit (node:events:390:28)\n' +
    '    at Fetch.terminate (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:77:10)\n' +
    '    at Object.onError (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:2027:34)\n' +
    '    at Request.onError (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/core/request.js:237:27)\n' +
    '    at errorRequest (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/client.js:1711:13)\n' +
    '    at Socket.onSocketClose (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/client.js:985:5)\n' +
    '    at Socket.emit (node:events:390:28)\n' +
    '    at TCP.<anonymous> (node:net:687:12)\n' +
    '    \n' +
    '        GraphQL Code Generator supports:\n' +
    '          - ES Modules and CommonJS exports (export as default or named export "schema")\n' +
    '          - Introspection JSON File\n' +
    '          - URL of GraphQL endpoint\n' +
    '          - Multiple files with type definitions (glob expression)\n' +
    '          - String in config file\n' +
    '    \n' +
    '        Try to use one of above options and run codegen again.\n' +
    '    \n' +
    '      ',
  source: 'src/',
  context: [Object: null prototype] {}
}
Something went wrong Failed to load schema for "src/"
        Failed to load schema from http://localhost/service:

        terminated
        TypeError: terminated
    at Fetch.onAborted (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:1893:49)
    at Fetch.emit (node:events:390:28)
    at Fetch.terminate (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:77:10)
    at Object.onError (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:2027:34)
    at Request.onError (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/core/request.js:237:27)
    at errorRequest (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/client.js:1711:13)
    at Socket.onSocketClose (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/client.js:985:5)
    at Socket.emit (node:events:390:28)
    at TCP.<anonymous> (node:net:687:12)

        GraphQL Code Generator supports:
          - ES Modules and CommonJS exports (export as default or named export "schema")
          - Introspection JSON File
          - URL of GraphQL endpoint
          - Multiple files with type definitions (glob expression)
          - String in config file

        Try to use one of above options and run codegen again.
`
mcollina commented 2 years ago

Thanks for reporting. Can you provide steps to reproduce with just Undici? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

d1urno commented 2 years ago

@Eddy84 I'm experiencing the same issue, did you manage to solve this?

d1urno commented 2 years ago

Downgrading node version from 18 to 16 (stable) did the trick for me.

LiamKarlMitchell commented 2 years ago

Same issue, but already on v16.14.0, v16.16.0 made no difference and it was working last week. Laravel Lighthouse + Graphql code gen.

hpiaia commented 2 years ago

@LiamKarlMitchell did you found any solution for that? I am trying to use it with Laravel Lighthouse and have the same problem. Node v16.16.0

thomasaull commented 2 years ago

@hpiaia Check my comment in this other issue https://github.com/dotansimha/graphql-code-generator/issues/7934#issuecomment-1166520696 for a workaround.

LiamKarlMitchell commented 2 years ago

Options request shouldn't have a Content-Length set.

Below is a middleware, which can be added to App/Http/Middlewares and put into lighthouse middlewares config array. It does add it to every POST request however for the graphql endpoint.

https://gist.github.com/LiamKarlMitchell/18f1e43ae6b772864d1b6a6ec1f71ba9

Works for me for a temp work-around until this can be resolved upstream.

On Thu, 28 Jul 2022, 11:05 am Thomas Aull, @.***> wrote:

@hpiaia https://github.com/hpiaia Check my comment in this other issue dotansimha/graphql-code-generator#7934 (comment) https://github.com/dotansimha/graphql-code-generator/issues/7934#issuecomment-1166520696 for a workaround.

— Reply to this email directly, view it on GitHub https://github.com/nodejs/undici/issues/1490#issuecomment-1197470332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPAP3INOG45VBBWVQLJTMTVWG6ERANCNFSM5YRKXXXA . You are receiving this because you were mentioned.Message ID: @.***>

hpiaia commented 2 years ago

@thomasaull @LiamKarlMitchell, I got another solution for that, just use node-fetch instead of undici for consuming the api.

schema:
  - http://localhost:8000/graphql:
      customFetch: 'node-fetch'

Reference: https://www.graphql-code-generator.com/docs/config-reference/schema-field#customfetch

mcollina commented 2 years ago

I'm closing this as won't fix. I will happy to review again when/if we have a reproduction for the problem.

thomasaull commented 2 years ago

@mcollina I'd be happy to provde a reproduction. However since this is happening in a mixedx project with php laravel and javascript, I'm not sure what would be the best way to do this?

mcollina commented 2 years ago

Try to reproduce with just undici and Node.js. Things that work well:

  1. use wireshark to see what's going on at the protocol level
  2. use net.createServer to reproduce that server
thomasaull commented 2 years ago

@mcollina Had no luck reproducing it with node :-/

michaelglass commented 1 year ago

happens periodically for us as well using node 18 with undici 5.22.1. No clear reproducer but we see it daily.

jacobshirley commented 1 year ago

Happens to us, using Node 20 in a Google Cloud Functions, however works fine locally

kevinrss01 commented 8 months ago

Happens also periodically for me using node 20 and nest.js - No clear reproducer but we see it daily. Happens only on long request (+15min)

Shabinder commented 8 months ago

+1, Affected by this, inconsistently, no defined cause.

undergroundwires commented 7 months ago

Happens when IPv6 is disabled. Reproduce on Ubuntu:

  echo '1' | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6 > /dev/null
  echo '1' | sudo tee /proc/sys/net/ipv6/conf/default/disable_ipv6 > /dev/null

Fetch usage with node results in exit code 13.