Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help #1080

Open
withmask opened this issue Feb 14, 2025 · 0 comments
Open

Help #1080

withmask opened this issue Feb 14, 2025 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@withmask
Copy link

withmask commented Feb 14, 2025

My fastfiy instance does not use the body returned by my custom error handler for request timeouts.

Specifically ones with fake content-length.

import fastify from 'fastify';
import axios from 'axios';

const instance = fastify({
  requestTimeout: 1000
});

instance.setErrorHandler((err, req, res) => {
  console.log(err);
  //This still logs.
  return {
    status: false,
    message: 'should be overwitten'
  };
});

instance.post('/', (req, res) => {
  console.log(req.body);
});

await instance.listen({
  host: '0.0.0.0',
  port: 8000
});
console.log('listened');

const x = await axios({
  method: 'POST',
  url: 'http://0.0.0.0:8000',
  headers: {
    'Content-Length': 16,
    'Content-Type': 'application/json'
  },
  data: 'a',
  validateStatus: () => true
});

console.log(x.data);
//Received body
/**
 * {
  error: 'Request Timeout',
  message: 'Client Timeout',
  statusCode: 408
}
 */

The logs from the instance are as follows.

listened
{
  error: 'Request Timeout',
  message: 'Client Timeout',
  statusCode: 408
}
Error: aborted
    at abortIncoming (node:_http_server:809:17)
    at socketOnClose (node:_http_server:803:3)
    at Socket.emit (node:events:536:35)
    at TCP.<anonymous> (node:net:350:12) {
  code: 'ECONNRESET',
  statusCode: 400
}

Your Environment

  • node version: 22.10.0
  • fastify version: 5.2.1
  • os: Linux
  • Running in a docker container.
@withmask withmask added the help wanted Extra attention is needed label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant