oracle / node-oracledb

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

Error with large number of binds, only in thin mode #1573

Closed Max-at-Prorank closed 1 year ago

Max-at-Prorank commented 1 year ago
  1. What versions are you using?
process.platform: win32 (also tested separately in a linux environment)
process.version: v18.12.1
process.arch: x64
require('oracledb').versionString: 6.0.1
require('oracledb').oracleClientVersionString: 19.10.0.0.0
  1. Is it an error or a hang or a crash?

Error

  1. What error(s) or behavior you are seeing?

The issue only happens in thin mode. Thick mode works fine. The specific error varies, oddly enough. The most common is NJS-103: unexpected message type 48 received while some other ones are NJS-103: unexpected message type 32 received or Cannot read properties of undefined (reading 'statement')

Error: NJS-103: unexpected message type 48 received
    at Object.throwErr (D:\Code\node_modules\oracledb\lib\errors.js:591:10)
    at ExecuteMessage.processMessage (D:\Code\node_modules\oracledb\lib\thin\protocol\messages\base.js:218:14)
    at ExecuteMessage.processMessage (D:\Code\node_modules\oracledb\lib\thin\protocol\messages\withData.js:89:13)
    at ExecuteMessage.process (D:\Code\node_modules\oracledb\lib\thin\protocol\messages\base.js:197:12)
    at ExecuteMessage.process (D:\Code\node_modules\oracledb\lib\thin\protocol\messages\withData.js:510:11)
    at ExecuteMessage.decode (D:\Code\node_modules\oracledb\lib\thin\protocol\messages\base.js:188:10)
    at Protocol._decodeMessage (D:\Code\node_modules\oracledb\lib\thin\protocol\protocol.js:77:17)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Protocol._processMessage (D:\Code\node_modules\oracledb\lib\thin\protocol\protocol.js:148:9)
    at async ThinConnectionImpl.execute (D:\Code\node_modules\oracledb\lib\thin\connection.js:796:5)
    at async Connection.execute (D:\Code\node_modules\oracledb\lib\connection.js:860:16)
    at async Connection.<anonymous> (D:\Code\node_modules\oracledb\lib\util.js:162:14)
  1. Include a runnable Node.js script that shows the problem.
connection = await pool.getConnection();

const sql = `
      BEGIN
        ${Array(150).fill(null).map((_, i) => `OPEN :v_out_${i}_0 FOR select :a_${i}, :b_${i}, :c_${i} from dual;`).join('\n        ')}
      END;
    `;

const params = Array(150).fill(null).map((_, i) => ({ [`a_${i}`]: 1, [`b_${i}`]: 2, [`c_${i}`]: 3, [`v_out_${i}_0`]: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } }))
      .reduce((a, x) => ({ ...a, ...x }), {});

await connection.execute(sql, params);

If you reduce the "150" to, for instance, 5 or 10, there is no error. If you remove all the in bind variables, there is no error.

connection = await pool.getConnection();

const sql = `
      BEGIN
        ${Array(5).fill(null).map((_, i) => `OPEN :v_out_${i}_0 FOR select :a_${i}, :b_${i}, :c_${i} from dual;`).join('\n        ')}
      END;
    `;

const params = Array(5).fill(null).map((_, i) => ({ [`a_${i}`]: 1, [`b_${i}`]: 2, [`c_${i}`]: 3, [`v_out_${i}_0`]: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } }))
      .reduce((a, x) => ({ ...a, ...x }), {});

await connection.execute(sql, params); // <---- No error
connection = await pool.getConnection();

const sql = `
      BEGIN
        ${Array(150).fill(null).map((_, i) => `OPEN :v_out_${i}_0 FOR select 1 from dual;`).join('\n        ')}
      END;
    `;

const params = Array(150).fill(null).map((_, i) => ({ [`v_out_${i}_0`]: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } }))
      .reduce((a, x) => ({ ...a, ...x }), {});

await connection.execute(sql, params); // <---- No error
anthony-tuininga commented 1 year ago

I can replicate the issue and will get back to you on the source of the problem!

Max-at-Prorank commented 1 year ago

Great, thank you for looking into it and the quick response.

sharadraju commented 1 year ago

@Max-at-Prorank The patch is available in lib/thin/protocol/messages/withData.js and will be incorporated in the 6.0.2 release. Please replace the above mentioned file in your repository and check again.

sharadraju commented 1 year ago

This is now available as part of node-oracledb 6.0.2. See the release announcement