title: Node.js server gets stuck after a few API calls
body: <p>I have a node.js application where I'm using the sign in functionality.
  I'm facing an issue; that is, when I try to sign in, sometimes the request gets stuck. It won't return anything until I refresh the node.js server. Can anybody take a look at the code and help me out what am I doing wrong here?</p>
  <p>Here is my Controller function</p>
  <pre><code> export const authenticate = async (
    req: Request,
    res: Response
  ): Promise&lt;void&gt; =&gt; {
    try {
      console.log(&quot;Login&quot;)
      const result: DataObject = await model.authenticate(
        req.body.username,
        req.body.password
      )
      const { status, data } = result
  
      res.status(status)
      if(status==200) {
        console.log(status)
        const u : User = data as User;
        const token = jwt.sign({ id: u.id }, process.env.JWT_SECRET as string)
        
        res.json({token: token})
        
      }
      else {
        res.json(data)
      }
    } catch (error) {
      res.status(NOT_FOUND)
      res.json(error)
    }
  }
  </code></pre>
  <p>And my Model method.</p>
  <pre><code> async authenticate(username: string, password: string): Promise&lt;DataObject&gt; {
      try {
        
        const sql =
          &quot;SELECT * FROM users WHERE username=$1&quot;
        const conn: PoolClient = await Client.connect()
  
        const result: QueryResult&lt;User&gt; = await conn.query(sql, [username])
        const { rows } = result
  
        if (rows.length &gt; 0) {
          
          const user: User = rows[0]
          const pepper: string = process.env.PASSWORD_HASH as string
          const pepperedPass = password + pepper;
          const validPass : boolean = bcrypt.compareSync(pepperedPass, user.password_digest);
         
          if (validPass) {
            const result: DataObject = {
              status: OK,
              data: user,
            }
            return result
          }
          else {
            const passErr: DataObject = {
              status: NOT_FOUND,
              data: &quot;Incorrect Password&quot;,
            }
            return passErr
          }
        }
        
        const userErr: DataObject = {
          status: NOT_FOUND,
          data: &quot;No User found with this Username&quot;,
        }
        return userErr
  
      } catch (error) {
        const userErr: DataObject = {
          status: NOT_FOUND,
          data: &quot;No User found with this Username&quot;,
        }
        return userErr
        throw new Error(`Not found, ${error}`)
      }
    }
  </code></pre>
  <p>I have tried <strong>res._destroy</strong>, <strong>res.set(&quot;Connection&quot;, &quot;close&quot;);</strong> but the issue persists.</p>
  <p>Any suggestion/solution is appreciated.</p>
  <p>Thank you.</p>