title: Pool is draining and cannot accept work : twice the same call in the same session?
body: <p>I have a last issue with my Node.JS code. I want to insert a user into my database (see below). When I test it with Postman the first time : Ok it works. BUT if I try again with different values, it doesn't and throw me this :</p>
  
  <pre><code>POST /users/create_account 500 3.735 ms - 1642
  Error: pool is draining and cannot accept work
  </code></pre>
  
  <p>So I don't understand why. There is the code below : (I Think there is no need to link my SQL code, if you need it, ask me :)) 
  I'm note using AWS by the way.</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  const { Pool, Client } = require('pg');
  const bodyParser = require('body-parser');
  
  const client = new Client({
    user: process.env.DB_DBUSER,
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    password: process.env.DB_PASS,
    port: process.env.DB_PORT,
  })
  
  const pool = new Pool({
    user: process.env.DB_DBUSER,
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    password: process.env.DB_PASS,
    port: process.env.DB_PORT,
  })
  
  pool.on('error', (err, client) =&gt; {
    console.error('Unexpected error on idle client', err)
    process.exit(-1)
  })
  
  //Third-party middelware
  router.use(bodyParser.json());
  router.use(bodyParser.urlencoded({
    extended: true
  }));
  
  /* CREATE an account */
  router.post('/create_account', function (req, response, next) {
  
    // Grab data from http request
    const data = {
      username: req.body.username,
      name: req.body.name,
      firstname: req.body.firstname,
      email: req.body.email,
      location: req.body.location
    };
  
    const values = [
      data.username,
      data.name,
      data.firstname,
      data.email,
      data.location
    ];
  
    pool.connect((err, client, done) =&gt; {
      if (err)
        throw err;
  
      client.query('INSERT INTO users(username, name, firstname, email, location) values($1, $2, $3, $4, $5)', values, (err, res) =&gt; {
        done();
  
        if (err) {
          throw err
        }
        response.send('USER' + res.rows[0] + 'SAVED');
        console.log('user:', res.rows[0]);
        pool.end()
      })
    });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Oc, in my postman body, I have this:</p>
  
  <pre><code>{
      "username" : "Username",
      "name" : "Bob",
      "firstname" : "Paul",
      "email" : "spfqqds@gmail.com",
      "location" : "Here"
  }
  </code></pre>
  
  <p>And my dependencies:</p>
  
  <pre><code>  "dependencies": {
      "body-parser": "^1.18.3",
      "cookie-parser": "~1.4.3",
      "debug": "~2.6.9",
      "dotenv": "^6.0.0",
      "express": "~4.16.0",
      "http-errors": "~1.6.2",
      "morgan": "~1.9.0",
      "pg": "^6.1.0",
      "pg-hstore": "^2.3.2"
    },
    "devDependencies": {
      "chai": "^4.1.2",
      "mocha": "^5.2.0"
    }
  </code></pre>
  
  <p>The SQL:</p>
  
  <pre><code>const queryUser = client.query(
    'CREATE TABLE IF NOT EXISTS Users('
    + 'user_id SERIAL,'
    + 'username VARCHAR(40) NOT NULL UNIQUE,'
    + 'name VARCHAR(40) NOT NULL,'
    + 'firstname VARCHAR(40) NOT NULL,'
    + 'email VARCHAR(60) UNIQUE,'
    + 'location Varchar(60) NOT NULL,'
    + 'CONSTRAINT pk_user PRIMARY KEY (user_id))',
  
    (err, res) =&gt; {
      if (err) throw err
      console.log("TABLE USERS : " + res)
    });
  </code></pre>