oracle / node-oracledb

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

await connection.tpcBegin(xid); command kills NodeJs server #1469

Closed riktamnandi closed 2 years ago

riktamnandi commented 2 years ago
  1. What versions are you using?

NodeJs v16.13.1 node-oracledb 5.3

Give your database version. Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Also run node and show the output of:

process.platform: win32
process.version: v16.13.1
process.arch: x64
require('oracledb').versionString: 5.3.0
require('oracledb').oracleClientVersionString: 12.1.0.2.0
  1. Describe the problem If I use Two Phase Commit, code then my NodeJS server automatically get closed or stopped. as soon as it execute -> await dbConnection.tpcBegin(xid); But, NodeJs must always be active/running state.
  1. Include a runnable Node.js script that shows the problem.

Please check my below query

CREATE TABLE MY_USERS_TABLE ( USER_ID VARCHAR2(30) NOT NULL, PASSWORD VARCHAR2(40) NOT NULL,

CONSTRAINT UK_MY_USERS_TABLE UNIQUE (USER_ID) );

Include all SQL needed to create the database schema.

Use a gist for long code: see https://gist.github.com/

Format code by using three backticks on a line before and after code snippets, for example:

const oracledb = require('oracledb');

async function run() { let dbConnection;

    // Transaction id
    let xid = {
        "formatId": 10,
        "globalTransactionId": "tx10",
        "branchQualifier": "br10"
    };

    try {

        // Connect to DB
        dbConnection = await oracledb.getConnection(dbCsctsConfig);

        // Start the transaction on DB
        await dbConnection.tpcBegin(xid);   
                    console.log("***** Problem start from here, when execute this line, it kills NodeJs server *****");                        

        const sql = "UPDATE MY_USERS_TABLE SET PASSWORD = STANDARD_HASH(:1, 'MD5') WHERE USER_ID = :2";

        // Perform some DML on database
        const result = await dbConnection.execute(sql, [newPassword, userId], {autoCommit:false});

        // Prepare DB
        const commitNeeded = await dbConnection.tpcPrepare(xid);

        if (commitNeeded) {                                        // Does DB need committing?
            console.log("Committing connection");
            await dbConnection.tpcCommit(xid);
        } else {
            console.log("Connection does not need no committing");
        }

        controllerCallback(null, result);
    }
    catch (err) {
        console.log(err);

        // Rollback on error
        if (dbConnection) {
            console.log("Rolling back Connection");
            await dbConnection.tpcRollback(xid);
        }           
        controllerCallback(err, null);          
    }
    finally {
        if (dbConnection) {
            try {
                console.log('Connection Closed...');                    
                await dbConnection.close();
            }
            catch (err) {           
                console.log(err);
                controllerCallback(err, null);
            }
        }
    }

}

run();

pvenkatraman commented 2 years ago
  1. Can you run test/tpc.js test case.
  2. Can you try with later version of instant client like 19.x. Thx.
stale[bot] commented 2 years ago

This issue has been automatically marked as inactive because it has not been updated recently. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically closed because it has not been updated for a month.