4

For a special use case with an express 4 server (forcing a client, that doesn't respond to 503 status code repeat a request) I need to not respond to a client request at all.

But Express sends a 502 Bad Gateway after apr. 2 minutes, when I just omit to send a result. How can I achieve this?

I tried to catch the timeout, but that doesn't help:

app.use((req, res, next) => {
  if (!req.timedout) {
    next();
    return;
  }

  console.log('Timeout!')
});
Michael
  • 6,823
  • 11
  • 54
  • 84
  • So you expressely need that the handling of this request by node.js ? Can't you filter it at a higher level ? (nginx / apache server, firewall ?) – Pac0 Nov 28 '17 at 13:48
  • No. I need to respond to certain conditions in the node.js server. – Michael Nov 28 '17 at 15:01
  • Interesting problem. Probably express in itself doesn't allow that, but you might be able to play and destroy the corresponding socket of the node.js connection (looks pretty dirty to me) . If you can't do that, you may anyway be able to set a special homemade response code in this case and filter the *response* with other admin tools on your server, instead of trying to filter the request. – Pac0 Nov 28 '17 at 15:16
  • BTW, this answer might work for you : https://stackoverflow.com/a/46157120/479251 (disable the timeout in the http module) – Pac0 Nov 28 '17 at 15:21
  • Why no just ignore the response on the client side? Or are you maybe not in charge of it? – Sello Mkantjwa Nov 28 '17 at 15:23
  • @SelloMkantjwa "_I need to not respond to a client request at all._" is expressly specified in the question – Pac0 Nov 28 '17 at 15:27
  • @Pac0 I see that. What I'm actually trying to figure out is why this would be the case - it is quite odd. Michael, what happens if you do respond? Would it be possible for you to tell us about this use case? – Sello Mkantjwa Nov 28 '17 at 16:36
  • @SelloMkantjwa The use case is an Atlassian Jira plugin, that provides some webhooks to a Jira connect server. In order to serve the requests it sometimes has to call a Rest API on that Jira connect server and for the case, that such requests time out, I like to have a retry mechanism. The Jira connect server has such retries inbuilt, if I don't respond at all, but doesn't react on 503 or 504 with retries. So a simple solution would be, so I thought, not to answer and so trigger the retries. Otherwise I would have to use a message queue and retry myself. – Michael Nov 29 '17 at 17:46

1 Answers1

0

Tell me if I didn't understand the question correctly...

You can use res.end();. That will end the request.

Klooven
  • 3,858
  • 1
  • 23
  • 41