Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NJS-500 connection lost #1695

Open
flash4174 opened this issue Sep 24, 2024 · 3 comments
Open

NJS-500 connection lost #1695

flash4174 opened this issue Sep 24, 2024 · 3 comments
Labels

Comments

@flash4174
Copy link

  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. Is it an error or a hang or a crash?

From time to time got njs-500 and I have to restart the Azure webserver to work again

  1. What error(s) or behavior you are seeing?
    Website can't connect to the database.
    Njs-500
    Ora-03135
  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 }

@flash4174 flash4174 added the bug label Sep 24, 2024
@sreguna
Copy link

sreguna commented Sep 24, 2024

@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
Copy link
Author

@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
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants