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

Encountered <NJS-018: invalid ResultSet> (it does not always happen) #1520

Closed zhaoanna closed 1 year ago

zhaoanna commented 1 year ago

1. What versions are you using? Node: 8+ oracledb: 4.2.0 Oracle DB: 12c or 19c

2. Describe the problem There is a project that uses queryStream() for data extraction from Oracle DB, for the same sql execution, it can be executed successfully in most of the time,tbut sometimes it ran to stream.on('error') stage with error: NJS-018: invalid ResultSet

Wonder if any suggestion on this case, thanks!

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

cjbj commented 1 year ago

Compare your code with the doc and examples to make sure you are not closing resources too early. Check the scope of things like connections to make sure you are not overwriting a connection prematurely.

cjbj commented 1 year ago

@zhaoanna PS it's time to update from Node 8 and node-oracledb 4.2 more recent versions.

zhaoanna commented 1 year ago

hi @cjbj , thanks for your quick reply, I checked and debuged that the connection closed correctly, the execution sequence was: get connection --> [ queryStream at stream.on('data') -> at stream.on('end')] -> close connection Normally, it should be stoped after "close connection", but in this case, it go into stream.on('error') after "close connection". It already returned expected result from stream.on('data'), and stream.on('end') is also executed, no idea why go into the stream.on('error').

On the other hand, I also found that when I extend the query time range which can get more data correctly (includes the data in the exception case above) and no that exception. No idea why....

Would like to know if the higher version is necessary for ORACLE 12C/19C? Thanks.

cjbj commented 1 year ago

You wrote

get connection --> [ queryStream at stream.on('data') -> at stream.on('end')] -> close connection

However the warning from examples/selectstream.js is

Note: do not close connections on 'end'.

You should only close connections after the Stream 'close' event.

zhaoanna commented 1 year ago

hi @cjbj, thank you so much for the kindly help, actually the 'close' event of connection does not on the 'end' event of stream. I wrote it into the 'then' after stream end and did not use the 'close' event of stream. However, I will change the code to follow the example standard see if it works. Thanks again.

zhaoanna commented 1 year ago

hi @cjbj, it works now. I guess it may because my original code returns the stream whole function at end event which causes the close connection event happens before destory stream event sometimes. (just guess) Thank you for your help!