restify / restify/node-restify

Error when response already destroyed

Open
#1,941 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.7k
Forks
975
Avg merge
1d 6h
Merged PRs (30d)
5

Description

  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Restify Version: 10.0.0
Node.js Version: 18.12.1

Expected behaviour

once the response is closed or sent to the client, the "chain handler" must be terminated

Actual behaviour

The "chain handler" still continues when the response has been destroyed

Repro case

case 1:

server.get('*',async(req, res) => {
console.log('----first----');
res.send('first');
}, async(req, res) => {
console.log('----second----');
res.send('second');
});

image

case 2:

server.get('*', async(req, res) => {
console.log('----first----');
res.send('first');
}, (req, res, next) => {
console.log('----second----');
res.send('second');
});

image

Cause

https://github.com/restify/node-restify/blob/adf24c1046022b1ed2a284556ff0cc9b1777ade2/lib/chain.js#L143

Are you willing and able to fix this?

yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at lib/chain.js around line 143, which the report identifies as the cause, and reproduce both request-handler cases from the issue. Trace how the chain proceeds after res.send or response destruction. Done means the chain handler terminates once the response is closed or sent, without invoking the second handler.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.