Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Manejo correcto del ciclo de vida de la conexión HTTP en solicitudes de ejecución prolongada

Tengo un proceso de E/S pesado que inicio al usar un punto final. Ese punto final debe responder inmediatamente al cliente que se ha iniciado el proceso.

La pesada tarea de E/S podría demorar hasta 30 minutos, por lo que me pregunto en qué estado deja la conexión entre el servidor y el cliente después de res.json(...) ? ¿La conexión del enchufe sigue abierta/medio abierta? ¿Debo, en este caso, destruir el socket manualmente después de res.json(...) ? ¿Está bien que la tarea heavyIO falle después de 29 minutos y vaya al controlador de errores express? Y finalmente; ¿Este patrón es incorrecto, por ejemplo, debo procesar las tareas de E/S de forma totalmente diferente?

A continuación se muestra un ejemplo mínimo:

 import express from 'express' const app = express() const asyncHandler = (handler) => (req, res, next) => Promise.resolve(handler(req, res, next)).catch(next) const heavyIO = () => new Promise((resolve, reject) => setTimeout(() => Math.random() > 0.5 ? resolve() : reject('FAILED'), 1000)) app.get('/start', asyncHandler(async (_req, res) => { // I want to be able to initiate the process and send back // confirmation that the process has been started. I want the // client to be able forget about this request. res.json('ok...started process') // Then we start to run the heavy IO process. Without the "await" this could // lead to unhandled promise rejection. // If this fails, the rejected promise will flow to express default // error handling which is I think "finalhandler" by default. // Because the headers as sent (res.headersSent === true) the error // handler will log the error and destroy the socket connection. // If this succeeds, the server will probably close the socket connection as well // internally. // Up until this point the socket has been open (or half-open?) so is this a problem? // Does it mean that the client has been "up-keeping" this socket connection // somehow or has/can it have been timed out before this succeeds or fails. await heavyIO() console.log(`FINISHED I/O at ${new Date().toISOString()}! Exiting handler...`) })) app.listen(8080)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!