ERR_STREAM_WRITE_AFTER_END when service is unavailable
See original GitHub issueWhen the gateway routes to a route that is unavailable, the gateway crashes and return ERR_STREAM_WRITE_AFTER_END
Steps to reproduce the behavior:
- Run the gateway normally with a route that doesn’t exists like localhost:8081
- Try to access the route calling it through the gateway, for example localhost:8081/v1/test/aa
- See error
Expected behavior
The gateway should return ‘Service unavailable’ error
Returned behavior
The gateway return ‘Service unavailable’ error but the gateway crashes with stack:
events.js:353
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at writeAfterEnd (_http_outgoing.js:694:15)
at ServerResponse.end (_http_outgoing.js:815:7)
at node_modules/fast-proxy-lite/index.js:95:19
at node_modules/fast-proxy-lite/lib/request.js:61:18
at node_modules/pump/index.js:75:7
at f (node_modules/once/once.js:25:25)
at ClientRequest.<anonymous> (/node_modules/pump/index.js:31:21)
at ClientRequest.f (node_modules/once/once.js:25:25)
at ClientRequest.onerror (node_modules/end-of-stream/index.js:44:12)
at ClientRequest.emit (events.js:388:22)
Emitted 'error' event on ServerResponse instance at:
at writeAfterEndNT (_http_outgoing.js:753:7)
at processTicksAndRejections (internal/process/task_queues.js:83:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
Additional context
The main.ts file:
/**
* The main class
*/
import * as gateway from 'fast-gateway'
const PORT = 8080
const server = gateway({
routes: [
{
prefix: '/v1/test',
target: 'http://localhost:8081'
}
]
}).start(PORT).then(() => {
console.log(`API Gateway listening on ${PORT} port!`)
})
package.json file:
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-ts": "tsc",
"build": "npm run build-ts",
"start": "node dist/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"fast-gateway": "^3.0.0"
},
"devDependencies": {
"@types/express": "^4.17.12"
}
}
tsconfig.json file:
{
"compilerOptions": {
"outDir": "dist",
"target": "es2017",
"module": "commonjs",
"sourceMap": true
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
bigquery/storage/write: getting error stream.Recv(): rpc error ...
The error is trying to communicate that the remote end of the grpc AppendRows grpc stream connection is going away. It is unclear...
Read more >java.io.IOException: unexpected end of stream on Connection ...
It means somehow execution returns to your client without the server sending actual response header. If you have control over server code, check ......
Read more >How to Fix 503 Service Unavailable Error: 7 Steps That Work
In this tutorial, learn what the 503 service unavailable error means and 7 proven methods to fix it to get your website back...
Read more >How to Fix the HTTP Error 503 Service Unavailable - Kinsta
The 503 (Service Unavailable) status code indicates that the server is currently unable to handle the request due to a temporary overload or ......
Read more >A Comprehensive Guide To Error Handling In Node.js
Errors happen in every application. Devs have to decide: do you write code to handle the error? Suppress it? Notify the user?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @jkyberneees
Many thanks! It’s fixed in v3.0.2 😃
Cheers!
Hi @iapain, very much appreciated. I will reproduce and push the fix ASAP.
@Gemerich Hope you're feeling better :)
+1