question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERR_STREAM_WRITE_AFTER_END when service is unavailable

See original GitHub issue

When the gateway routes to a route that is unavailable, the gateway crashes and return ERR_STREAM_WRITE_AFTER_END

Steps to reproduce the behavior:

  1. Run the gateway normally with a route that doesn’t exists like localhost:8081
  2. Try to access the route calling it through the gateway, for example localhost:8081/v1/test/aa
  3. 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:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iapaincommented, Dec 30, 2021

Hi @jkyberneees

Many thanks! It’s fixed in v3.0.2 😃

Cheers!

1reaction
jkyberneeescommented, Nov 25, 2021

Hi @iapain, very much appreciated. I will reproduce and push the fix ASAP.

@Gemerich Hope you're feeling better :) +1

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found