Node express request closed before oracle query finished execution

I am using node and express and oracle as my DB. My application works fine. To do a load test of my application i run Apache ab benchmark. When i try concurrent connections say 100 requests, final couple of requests fail, when i debugged via loggers, i saw that request.on('close') is called on and then the query completes its execution. This happens only for final four to five requests. Is there a way to handle it. My Oracle pool consists of one connection. I use node-oracle for connection.

My codebase is a clone from

expect that poolMax and poolMin is 1.

Apache Benchmark command i run.

ab -k -c 30 -n 200 http://localhost:3000/api/abc/91

In index.js i have added below to track status of http request. It goes into close code and then prints the query execution result.

const getLoggerForStatusCode = (statusCode) => {
  if (statusCode >= 500) {
    return console.error.bind(console)
  if (statusCode >= 400) {
    return console.warn.bind(console)

  return console.log.bind(console)

const logRequestStart = (req, res, next) => {
  req.requestId = token(true).substr(0, 8)

  res.on('timeout', function () {
    console.log("timeout! " + (options.timeout / 1000) + " seconds expired");


req.on('error', function (err) { 
  console.log('request error'+ error);
});`[${req.requestId}] ${req.method} ${req.originalUrl}`)

  res.setTimeout(5000000, function () {
    // call back function is called when request timed out.
    console.log('server timed out');

  const cleanup = () => {
    res.removeListener('finish', logFn)
    res.removeListener('close', abortFn)
    res.removeListener('error', errorFn)

  const logFn = () => {
    const logger = getLoggerForStatusCode(res.statusCode)
    logger(`[${req.requestId}] ${res.statusCode} ${res.statusMessage}; ${res.get('Content-Length') || 0}b sent`)

  const abortFn = (err) => {
    console.warn(`[${req.requestId}] Request aborted by the client ${err}`)

  const errorFn = err => {
    console.error(`Request pipeline error: ${err}`)

  req.on('finish', logFn) // successful pipeline (regardless of its response)
  req.on('error', errorFn) // pipeline internal error
  req.on('close', abortFn) // aborted pipeline



I did measure the time and after 7 seconds from the time request was received, connection got closed.