sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

connection: "keep-alive" header in http2 mode causes ERR_INTERNAL_ASSERTION #1659

Closed andrisi closed 3 years ago

andrisi commented 3 years ago

Describe the bug

Adding a connection: "keep-alive" header in http2 mode causes ERR_INTERNAL_ASSERTION

Actual behavior

ERR_INTERNAL_ASSERTION

Expected behavior

Perhaps ignore silently or warn that it is inapropriate?

Code to reproduce

    let result = await got('https://http2.pro/api/v1', {
        http2: true,
        responseType: 'json',
        headers: {
            connection: "keep-alive"
        }        
    })

Checklist

szmarczak commented 3 years ago

Can you try the main branch instead? 11.8.2 still uses an old version of http2-wrapper

andrisi commented 3 years ago

I have http2-wrapper 2.0 in the project too as I initially tried with that as an agent, but then saw it fails without that in the request too. If that is not enough, I'd try later.

xamgore commented 3 years ago

Got the same error. Upgrading to Node v15.12.0 and changing the package.json fixed it:

"got": "sindresorhus/got#main",
duongvanba commented 3 years ago

Got the same error. Upgrading to Node v15.12.0 and changing the package.json fixed it:

"got": "sindresorhus/got#main",

i think we need to build before use How to build that ?

duongvanba commented 3 years ago

Error: Cannot find module '/****/node_modules/got/dist/source'. Please verify that the package.json has a valid "main" entry

szmarczak commented 3 years ago

How to build that ?

npm run build

duongvanba commented 3 years ago

Many thanks Can you tell me why I can't install by yarn I need to use 'npm install' instead, with that I can see dist folder built It just clone repo when use "yarn install"

szmarczak commented 3 years ago

Can you tell me why I can't install by yarn

I have no idea, probably something related to your environment.

andrisi commented 3 years ago

this is still an issue with node 15.12

`Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals. Please open an issue with this stack trace at https://github.com/nodejs/node/issues

at new NodeError (node:internal/errors:329:5)
at assert (node:internal/assert:14:11)
at ClientRequest.Writable.destroy (node:internal/streams/writable:851:5)
at Request._destroy (C:\Develop\mastercompare\node_modules\got\dist\source\core\index.js:1368:32)
at _destroy (node:internal/streams/destroy:67:23)
at Request.destroy (node:internal/streams/destroy:59:5)
at Request._error (C:\Develop\mastercompare\node_modules\got\dist\source\core\index.js:1190:14)
at C:\Develop\mastercompare\node_modules\got\dist\source\core\index.js:1270:23 {

code: 'ERR_INTERNAL_ASSERTION' }`

szmarczak commented 3 years ago

@andrisi I've just tested with http2-wrapper@2.0.0 and I'm getting a different error:

const http2 = require('http2-wrapper');
const got = require('got');

try {
    await got('https://http2.pro/api/v1', {
        http2: true,
        responseType: 'json',
        request: http2.auto,
        headers: {
            connection: "keep-alive"
        }        
    });
} catch (error) {
    console.error(error.stack);
}
Error [ERR_STREAM_DESTROYED]: Cannot call end after a stream was destroyed
    at new NodeError (node:internal/errors:329:5)
    at errorBuffer (node:internal/streams/writable:527:14)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)
xamgore commented 3 years ago

this is still an issue with node 15.12

Make sure you have the correct version in node_modules/got/package.json and the same with http2-wrapper.

szmarczak commented 3 years ago

Fixed: https://github.com/szmarczak/http2-wrapper/commit/93f36ef298706a950ae65be08fb57df241a75655

Will publish a new version of http2-wrapper later today.

andrisi commented 3 years ago

Thanks @szmarczak ! Will you update got too, it seems to use an internal version of http2-wrapper.