oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.26k stars 1.08k forks source link

NJS-500 connection lost #1695

Open flash4174 opened 1 month ago

flash4174 commented 1 month ago
  1. What versions are you using? node-oracle V6.6.0 nodeJS 18 Oracle instant client 23.5.0. Express 4.18.2 nextJS 14.2.4 Oracle database: 19c
    1. Include a runnable Node.js script that shows the problem. server.js
    const next = require(‘next’)
    const express = require(‘express’)
    const userRoutes = require(‘/routes/userRoutes’)
    const OracleDB = require(‘oracledb’)
    const dbConfig = require(‘./config/dbConfig’)
    
    OracleDB.initOracleClient()
    
    const port = 3000
    const dev = false
    const app = next({dev})
    
    const handle = app.getRequestHandler()
    
    process.env.UV_THREADPOOL_SIZE = 4 + dbConfig.poolMax
    
    app.prepare().then(() => {
         OracleDB.createPool(dbConfig).then(() => {
    
              const server = express()
              server.use(cookieParser())
              server.use(express.json({limit: “20mb”}))
    
               server.use(‘/api/user/‘, userRoutes)
    
              server.all(‘*’, (req, res) => {
                  return handle(req,res)
               })
    
               server.listen(port, (err) => {
                   if(err) throw err
                   console.log(‘server ready on port 3000’)
               })
        })
    })
    

    dbConfig

    const dbConfig = {
          user: “username”,
          password: “pass”,
          connectString: “connetction string with enable=broken”,
          poolMax: 30,
          poolMin: 30,
          poolAlias: “mainPool”,
          retryCount: 3,
          expireTime: 3,
          poolPingInterval: 0
    }
    
    module.exports = dbConfig

    UserRoutes

    const express = require(‘express’)
    const router = express.Router()
    
    const { getUsers } = require(‘../controllers/userController’)
    
    router.route(‘/‘).get(getUsers)
    
    module.exports = router
    

    UserController

    
    const asyncHandler = require(‘express-async-handler’)
    const OracleDB = require(‘oracledb’)
    
    const getUsers = asyncHandler(async(req, res) => {
       let connection = await OracleDB.getConnection(‘mainPool’)
       try {
           const sql = ‘select query’
           const result = await connection.execute(sql)
           If(result){
              res.status(200).json(result)
            }else {
               res.status(401)
            }
        catch(error) {
           console.log(error)
        }
        finally {
            if(connection) {
                try{
                    await connection.close()
                } catch {
                    console.log(error)
                }
              }
           }
    })
    
    module.exports = { getUsers }
    
sreguna commented 1 month ago

@flash4174 instead of (enable=broken) which uses system defaults can you use (expire_time=n) under the DESCRIPTION section of the connect string. The value(n) is in minutes.

flash4174 commented 3 weeks ago

@flash4174 instead of (enable=broken) which uses system defaults can you use (expire_time=n) under the DESCRIPTION section of the connect string. The value(n) is in minutes.

Thank you for the answer. Now I receive njs-040 time to time.

Do you have any idea?

sudarshan12s commented 2 weeks ago

@flash4174 instead of (enable=broken) which uses system defaults can you use (expire_time=n) under the DESCRIPTION section of the connect string. The value(n) is in minutes.

Thank you for the answer. Now I receive njs-040 time to time.

Do you have any idea?

@flash4174 , If queueTimeout is less, then timeout can happen. Can you adjust it . It normally comes if all connections are busy and poolMax is reached. Hence new connections get timeout error. poolMax can be increased if active/busy connections at any point are large.

some details here