Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Regression in 3.1.0: isConnectionError does not treat NJS-500 / NJS-521 as connection errors (npm published from older commit) #6282

@xenon-ua

Description

@xenon-ua

Background

The knex package published to npm as v3.1.0 was built from commit
4ca3dd5bc28e0665c5bed55026fac2ec45489d81. That commit's
lib/dialects/oracle/utils.js does not include handling for NJS-500
(and NJS-521) in isConnectionError(error). The master branch's
lib/dialects/oracle/utils.js however does contain logic for NJS-500
code (so the repository shows different contents than the npm tarball) but does not handle NJS-521.

This causes knex to not evict broken Oracle connections when the
driver returns new NJS error codes (for example NJS-500), leaving the
pool filled with dead connections after a brief outage.

Because NJS-521 is an EOF/communication-channel error from the
node-oracledb driver (e.g. "received end-of-file on communication
channel"), it should be treated as a connection-level error so the pool
will evict that connection.

Reproduction / verification steps

  1. npm view [email protected] gitHead — shows 4ca3dd5b... (the published gitHead)
  2. npm pack [email protected] && tar -xzf knex-3.1.0.tgz — inspect
    package/lib/dialects/oracle/utils.js and see that NJS-500/NJS-521
    handling is missing from isConnectionError
  3. Compare with the file on GitHub:
    https://github.com/knex/knex/blob/master/lib/dialects/oracle/utils.js
    (the master file contains the NJS handling)

Actual behavior

When oracledb returns NJS-500 / NJS-521 during an outage, knex
doesn't classify the error as a connection error. Because of that, tarn
pooling will not destroy/evict the broken connection objects and the app
keeps receiving failing connections even after the DB becomes reachable again.

Expected behavior

isConnectionError should classify NJS-500 and related NJS-* codes
from oracledb as connection errors so the pool will destroy those
connections and allow new healthy connections to be created.

Suggested minimal fix

Ensure isConnectionError(error) recognizes NJS error codes, for
example:

// inside lib/dialects/oracle/utils.js (isConnectionError)
function isConnectionError(err) {
  return [
    'DPI-1010', // not connected
    'DPI-1080', // connection was closed by ORA-%d
    'ORA-03114', // not connected to ORACLE
    'ORA-03113', // end-of-file on communication channel
    'ORA-03135', // connection lost contact
    'ORA-12514', // listener does not currently know of service requested in connect descriptor
    'ORA-00022', // invalid session ID; access denied
    'ORA-00028', // your session has been killed
    'ORA-00031', // your session has been marked for kill
    'ORA-00045', // your session has been terminated with no replay
    'ORA-00378', // buffer pools cannot be created as specified
    'ORA-00602', // internal programming exception
    'ORA-00603', // ORACLE server session terminated by fatal error
    'ORA-00609', // could not attach to incoming connection
    'ORA-01012', // not logged on
    'ORA-01041', // internal error. hostdef extension doesn't exist
    'ORA-01043', // user side memory corruption
    'ORA-01089', // immediate shutdown or close in progress
    'ORA-01092', // ORACLE instance terminated. Disconnection forced
    'ORA-02396', // exceeded maximum idle time, please connect again
    'ORA-03122', // attempt to close ORACLE-side window on user side
    'ORA-12153', // TNS'not connected
    'ORA-12537', // TNS'connection closed
    'ORA-12547', // TNS'lost contact
    'ORA-12570', // TNS'packet reader failure
    'ORA-12583', // TNS'no reader
    'ORA-27146', // post/wait initialization failed
    'ORA-28511', // lost RPC connection
    'ORA-56600', // an illegal OCI function call was issued
    'NJS-024',
    'NJS-003',
    'NJS-500',
    'NJS-521',
  ].some(function (prefix) {
    return err.message.indexOf(prefix) === 0;
  });
}

Request
Please update isConnectionError in the release branch/tag used for npm
publishing so that the npm tarball content and GitHub master become
consistent.

Publish a patch release (e.g. 3.1.1) including this fix — many
users experience stalled pools after transient Oracle outages.

Evidence / references
npm package page (code tab): https://www.npmjs.com/package/knex?activeTab=code

GitHub file (master): https://github.com/knex/knex/blob/master/lib/dialects/oracle/utils.js

Published gitHead for 3.1.0: 4ca3dd5 (this commit lacks NJS handling)

If helpful I can open a small PR with the minimal change and a test
case (simulate an error object with code: 'NJS-500' and assert that the
function returns true). Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions