title: NodeJS Mysql pool.query() not releasing connections?
body: <p>I am having trouble with pooling mysql connections with nodeJS. As I understand it, when creating a pool, I should be able to use pool.query() to:</p>
  <ol>
  <li>Get a connection</li>
  <li>Run my query</li>
  <li>Release the connection</li>
  </ol>
  <p>However, the issue I am running into is the connections remain open and &quot;sleeps&quot; until the server closes the connection itself (60 seconds). Is there something I am doing wrong here? For context, I am connecting to Heroku clearDB and am viewing the connection on its dashboard.</p>
  <p>Example: Upon login, I make a query to check login credentials to authenticate, another query to fetch one set of data, and another query to fetch another set. After logging in, the server is left with 2 connection in &quot;sleep&quot; mode. They do not disconnect until 60 seconds expire.</p>
  <p>Here is my db.js file:</p>
  <pre><code>const mysql = require(&quot;mysql&quot;);
  
  const dbConfig = require(&quot;./db.config.js&quot;);
  
  const connection = mysql.createPool({
      host: dbConfig.HOST,
      user: dbConfig.USER,
      password: dbConfig.PASSWORD,
      database: dbConfig.DB,
      port: dbConfig.PORT,
      multipleStatements: true,
      connectionLimit: 10
  })
  
  module.exports = connection;
  
  </code></pre>
  <p>Here is how I am making queries:</p>
  <pre><code>const sql = require(&quot;./db.js&quot;); //Our db connection
  ---OMITTED---
  return new Promise((resolve, reject) =&gt; {
          const select_user = &quot;SELECT user_id, first_name, last_name, username, password, is_admin, is_active FROM users WHERE username = ? LIMIT 1&quot;
          const params = [username]
          const user_pass = password
  
          sql.query(select_user, params, (err, res) =&gt; {
              if (res) {
                  if (res.length) {
                      const user = res[0]
                      const hash = user.password
                      const is_active = user.is_active
                      if (is_active) {
                          bcrypt.compare(user_pass, hash).then(res =&gt; {
                              if (res) {
                                  resolve({ result: true, info: { fname: user.first_name, lname: user.last_name, username: user.username, is_admin: user.is_admin, user_id: user.user_id } })
                              } else {
                                  reject({ result: false, msg: &quot;wrong_creds&quot; })
                              }
                          }).catch(err =&gt; {
                              reject({ result: false, msg: err })
  
                          })
                      } else {
                          reject({ result: false, msg: &quot;inactive&quot; })
                      }
  
  
                  } else {
                      reject({ result: false, msg: &quot;user_not_exist&quot; })
                  }
  
              } else {
                  console.log(&quot;MYSQL QUERY, COULD NOT SELECT USER FOR AUTHENTICATION&quot;)
                  reject({ result: false, msg: err })
              }
          })
  
  
  })
  </code></pre>
  <p>I'm under the impression that pool.query() will close the connection for me after each query. Is this not the case? Am I missing something once the query has been completed?</p>
  <p>I have also tried the manual way:</p>
  <pre><code>        const select_string = &quot;SELECT * FROM user_backlogs WHERE movie_id = ? AND user_id = ?&quot;
          const params = [movie_id, user_id]
          sql.getConnection((err, connection) =&gt; {
              if (err) reject(err)
              else {
                  connection.query(select_string, params, (err, res) =&gt; {
                      connection.release()
                      if (err) reject(err)
                      else {
                          if (res.length) {
                              resolve([movie_id, &quot;exists&quot;, res[0][&quot;added_on&quot;]])
                          } else {
                              resolve([movie_id, &quot;not_exists&quot;])
                          }
                      }
                  })
              }
          })
  </code></pre>
  <p>But still, the connections remain up until the server kicks them off. Any help is greatly appreciated.</p>