node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

Unable to run on Thick mode when using Bun runtime

Open luizvergennes opened this issue 1 year ago • 3 comments

1. What versions are you using?

  • Oracle Database 18 and 19
  • OracleDB Package 6.5.1
  • Linux x64
  • Oracle Client 21_9

2. Is it an error or a hang or a crash?

It is a crash when trying to start a pool or a connection.

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

I was using the example.js file provided on the node_modules/oracledb/examples folder. I ran the following command:

NODE_ORACLEDB_USER=*** \
NODE_ORACLEDB_PASSWORD=*** \
NODE_ORACLEDB_CONNECTIONSTRING=*** \
NODE_ORACLEDB_DRIVER_MODE=thick \
bun run example.js

Which instantly resulted in the following error:

Running in thick mode
638 |     _initializeThinDriver();
639 |   }
640 |
641 |   const conn = new Connection();
642 |   conn._impl = new impl.ConnectionImpl();
643 |   await conn._impl.connect(options);
              ^
error: internal error in file ../src/njsUtils.c, line 805 ()
      at /home/***/Dev/***/node_modules/oracledb/lib/oracledb.js:643:9

4. Include a runnable Node.js script that shows the problem.

It is provided on the examples folder of the package.

luizvergennes avatar Jun 13 '24 13:06 luizvergennes

Looking at the line number in the C code the failure is occurring during a call to napi_wrap(). That sounds like it could be a problem with the Bun runtime itself?

anthony-tuininga avatar Jun 13 '24 13:06 anthony-tuininga

My bun runtime was on version 1.1.8. Upgraded it to 1.1.13 but the issue persists.

I will also be creating an issue on Bun's repository to receive some feedback from them.

luizvergennes avatar Jun 13 '24 16:06 luizvergennes

Can confirm this is still present testing on v1.1.22-canary.96+df33f2b2a (Windows x64)

pg-wtatum avatar Aug 13 '24 15:08 pg-wtatum

@Luk4h @pg-wtatum I was able to replicate this issue in a separate test case without node-oracledb. This probably means that it is an issue with BUN and napi functions. See the attached test case. (You need a C compiler also) bunerror.zip

In the attached example, you will see that the issue occurs when we pass the jsObject as the thisArg argument to the [napi_cb_get_info](https://nodejs.org/dist/v23.3.0/docs/api/n-api.html#napi_get_cb_info) function before we call the napi_wrap function in the C file. It does not occur if the jsObject is created using napi_create_object().

When we run the code with node myscript.js There is no error. But with bun run myscript.js, it gives an error with napi_wrap with status 2 (napi_object_expected).

I believe this issue has got to do the with following bun change made for a previous issue: https://github.com/oven-sh/bun/commit/1dac9248aded80aaa7ea213439f4fdb3c58777a4#diff-ac0007aca96a4451f059649ba8c9b25303aeed7dc6d818f41ee39172a4b6eef0R537

I will post this in the corresponding Bun issue as well.

sharadraju avatar Dec 05 '24 09:12 sharadraju

Closing this issue as this is BUN related.

sharadraju avatar Dec 17 '24 13:12 sharadraju

For future reference, this seems fixed on Bun.js v1.2.12.

luizvergennes avatar May 14 '25 11:05 luizvergennes