Ad

POST Request Being Aborted After A Long Time

My express app has a route /api/uploadSbml which expects a multipart/form type post request in which I upload a file.

Locally running, everything works fine, but when I deploy the code to a server on digital ocean, the request is aborted by the server after a solid 2 minutes.

I've tried using other uploading libraries like multer, express-fileupload all resulting in the same issue.

The route file which applies the formidable middleware:

// Route
const express = require('express')
const formidableMiddleware = require('express-formidable')
const uploadSbmlController = require('../controllers/uploadSbml')
const router = express.Router()

// Formidable middleware for uploading files
router.use(formidableMiddleware({ uploadDir: './' }))

router.post('/', uploadSbmlController)

module.exports = router

The controller file which uses the file uploaded:

// Controller
module.exports = function(req, res) {
  if (req.files.file) {
    // do stuff
  } else {
    res.status(500).send('Something went terribly wrong.')
  }
}

The error received after nearly 2 minutes at the server:

Error: Request aborted
     at IncomingMessage.<anonymous>(/usr/src/app/server/node_modules/formidable/lib/incoming_form.js:122:19)
     at IncomingMessage.emit (events.js:198:13)
     at abortIncoming (_http_server.js:448:9)
     at socketOnClose (_http_server.js:441:3)
     at Socket.emit (events.js:203:15)
     at TCP._handle.close (net.js:606:12)
Ad

Answer

A quick search for "express two minute timeout" reveals that Express (actually the underlying node.js HTTP module) has a default two minute timeout.

According to the current node.js documentation, this can be adjusted by calling server.timeout(<new timeout value in milliseconds>).

It sounds like the file you're uploading is large enough that, although it uploads quickly on your local network, it takes more than two minutes when uploading to the remote server.

Ad
source: stackoverflow.com
Ad