I'm encountering a problem using the 'callback' form of 'connect' in the JavaScript External Environment. The problem is that the callback code doesn't seem to be executed. If I use the synchronous version of 'connect', things work as expected. I have greated a github gist at (https://gist.github.com/twilkinson/00748d66bef5fff91852) that illustrates the problem. There are 2 files:
You can see the output in *C:\Temp\tests.log". All that shows in tests.log are the lines start of test1A end of test1Awhere I would expect to also see the first 10 lines of the Customers table. It is acting as if the script is terminated without waiting for the asynchronous code to complete. If I run similar code under nodejs directly, it behaves as I would expect with the first 10 lines of the Customer table showing up in the output file. This occurs with the latest SA17 Developer Edition under both Windows and Linux. Suggestions? Thanks, |
Which node.js version are your using. A coworker of mind could not reproduce your other issue with the latest node.js (5.6.0) where I was using nodejs (4.3.0).
Maybe this is a pure NodeJS version issue. Have you tried it wih the newer NodeJS downloads available?
FWIW I can reproduce this with v4.3.0 and it appears with that version, code executed within the body of your callback function will not run with that. (Request logging at the server show no query is submitted) Extracting the Prepare and Execute operations from that exception handling scope, and placing it back out to the same scope as the connect does work so that tends to confirm this may be a NodeJS runtime issue.
Hopefully this issue will also be resolved with V5.6.0 or something newer.
I should have mentioned that I'm running nodejs 0.10.40 - waiting for the update to the SA17 Developer Edition for node 4+ support.
FYI, I just tried this under Linux (Ubuntu 14.04) with SA17 build 1358 and node v5.6.0. Unfortunately, I still get the behaviour described in my initial post.
If I run substantially the same code (see testA2.js at https://gist.github.com/twilkinson/00748d66bef5fff91852 ) from the linux command line:
it performs as you would expect, writing the database SELECT results to the file.
It looks to me that for some reason, NodeJS terminates early when called from SA17, and doesn't wait for it's event loop to complete.