Problems with HTTP/2 Invalid Stream
FuyukiWolfer opened this issue · 8 comments
Version: 11.11.0
OS: Windows 10 Home (64-bit)
I am using Fastify HTTP Proxy to get the CDN (S3 + Cloudfront) files and avoid CORS or CSP problems, but sometimes the request fail and generate a error ERR_HTTP2_INVALID_STREAM
that crash de Node.js Application, so i started observe that and always the request that crash the app was from the proxy.
This error decreases a lot, but even so it still occurs, and in addition another error began to appear the HTTP2_ENHANCE_YOUR_CALM
that after the error all requests from the proxy result in a Internal Server Error (Code: 500) and the only way to resolve that is restarting the app.
To try resolve this error, i used GZIP compression from the Cloudfront Server to not compress the files from the CDN by the Fastify Compress, this helped a lot, a way to bypass the Invalid Stream Error is using a UncaughtException what is not secure to use, handling the error the requests throw the error but the app works, the files load and not crash, but i really not want continue doing that.
The normal routes from the Fastify works fine, the only problem is that error that can occur any time, not guaranteeing the stability of the application. So how can i fix that?
Note: I am starting work with JS and Node.js recently, so i may have done something wrong, you can check the code that i am using on my profile, the name is ACS. Thanks!
Error [ERR_HTTP2_INVALID_STREAM]: The stream has been destroyed
at Http2ServerResponse.write (internal/http2/compat.js:606:19)
at IncomingMessage.ondata (_stream_readable.js:693:20)
at IncomingMessage.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at IncomingMessage.Readable.push (_stream_readable.js:224:10)
at HTTPParser.parserOnBody (_http_common.js:126:22)
at TLSSocket.socketOnData (_http_client.js:447:20)
at TLSSocket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at TLSSocket.Readable.push (_stream_readable.js:224:10)
at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)
Error [ERR_HTTP2_INVALID_STREAM]: The stream has been destroyed
at Http2ServerResponse.write (internal/http2/compat.js:606:19)
at Duplexify.ondata (C:\Users\Wolfer\Documents\App\node_modules\readable-stream\lib\_stream_readable.js:619:20)
at Duplexify.emit (events.js:197:13)
at addChunk (C:\Users\Wolfer\Documents\App\node_modules\readable-stream\lib\_stream_readable.js:291:12)
at readableAddChunk (C:\Users\Wolfer\Documents\App\node_modules\readable-stream\lib\_stream_readable.js:278:11)
at Duplexify.Readable.push (C:\Users\Wolfer\Documents\App\node_modules\readable-stream\lib\_stream_readable.js:245:10)
at Duplexify._forward (C:\Users\Wolfer\Documents\App\node_modules\duplexify\index.js:170:26)
at Gzip.onreadable (C:\Users\Wolfer\Documents\App\node_modules\duplexify\index.js:134:10)
at Gzip.emit (events.js:197:13)
at emitReadable_ (_stream_readable.js:539:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
Looks like a bug. Which version of Node.js are you using? Can you please add some instructions on how to reproduce using your repo?
I am using Node.js 11.11.0
About the repository, you can download the last release, go to settings.yml and do this changes:
# Content Delivery Network (CDN)
cdn:
# Enable CDN
enabled: true
# Endpoint
endpoint: altair.projectasterk.com
# Enable HTTP/2
http2: true
# Enable Compress
compress: true
After this you can go to index.hbs and add to the code this:
<!--Style-->
<link href="/cdn/font/open-sans.css" rel="stylesheet">
<link href="/cdn/framework/bootstrap/4.3.1/bootstrap.min.css" rel="stylesheet">
<!--Script-->
<script src="/cdn/framework/jquery/3.3.1/jquery.min.js"></script>
<script src="/cdn/framework/popper/1.14.7/popper.min.js"></script>
<script src="/cdn/framework/bootstrap/4.3.1/bootstrap.min.js"></script>
<script src="/cdn/framework/fontawesome/5.7.1/fontawesome.min.js"></script>
Finished execute npm test and go to https://localhost:3000
How i said the error can occur any time, some times occur in the first request and others in the 100th request for example.
If you want enable the error stack for Invalid Stream, go to server.js and remove that line:
//if (err.name === 'Error [ERR_HTTP2_INVALID_STREAM]') return log('Server: HTTP/2 Invalid Stream', 'erro');
Now i got the message from the HTTP2_ENHANCE_YOUR_CALM
error:
{"statusCode":500,"code":"ERR_HTTP2_STREAM_ERROR","error":"Internal Server Error","message":"Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM"}
Hi @FuyukiWolfer
I cloned your project then I modified it according your comment.
But I can not produce the error.
After running npm test how can I send request to server?
I go to https://localhost:3000. after thet I refresh page some times. Is it enough?
Hi @srmarjani, you can force the issue executing sometimes this autocannon -a 40 https://localhost:3000/cdn/app/pcomunic/img/index/cover.jpg
for example, when you see that the request finish with status 500 is because occur HTTP2_ENHANCE_YOUR_CALM
error, and the ERR_HTTP2_INVALID_STREAM
how i said is randomly, i will try find a way to get this error, if i find i will comment here.
Does this still reproduce? It's supposed to be fixed here:
nodejs/node#27682
In theory yes. Closing for now, it might be we should reopen in case it's still a problem.