oracledb connection hangs without successfully callback returned
Hi Oracle experts,
I had a challenge that couldn't establish a successfully connection to Oracle DB in the Docker container with the OS as ubuntu 18.04 (the basic Docker image).
The connection keep hanging forever without success callback returned, however, it could return the error messages. e.g, if I use the bad credentials. it will get the error response as below:
{ [Error: ORA-01017: invalid username/password; logon denied] errorNum: 1017, offset: 0 },
When I use the right credentials, it hangs forever. I am using the below node script for testing the connection and execution.
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : <username>,
password : <password>,
connectString : "<hostname>:<port>/<instance>"
},
function(err, connection)
{
if (err) { console.error(err); return; }
console.log('Succeed connected..' + JSON.stringify(connection));
connection.execute(
<SQL QUERY>
function(err, result)
{
if (err) { console.error(err); return; }
console.log(result.rows);
});
});
Ubuntu: 18.04 Node version: 10.18.0 OracleDB package: 4.1 instantclient: 12_1 or 19_5
Please note, I was able to connect to it successfully in below two cases:
- In the ubuntu 18.04 C2C machine with the same node and oracleDb versions. (Not a mini ubuntu Docker image).
- In the Docker container with node as the base image (which has the debian OS )
The returned connection objects should be something like this:
Succeed connected..{"_events":{},"_eventsCount":1,"_dbObjectClasses":{},"_pool":{"_events":{},"_eventsCount":1,"queueTimeout":60000,"poolAlias":"default","status":6000}}
Based on above two successful cases, I am suspecting that the ubuntu base image has some issues which blocks the oracle connection. Such as need more tools to installed or it does not work at all. Here is the Dockerfile I am using.
FROM <Artifactory server>/ubuntu:18.04
# Create app directory.
RUN mkdir -p /usr/src/ultraaschedulingapp
WORKDIR /usr/src/ultraaschedulingapp
# Bundle app source.
COPY . /usr/src/ultraaschedulingapp
# Get oracledb build dependencies.
RUN echo 'Acquire::http::Proxy "<Corporate Proxy>' >> /etc/apt/apt.conf
RUN echo 'Acquire::https::Proxy "<Corporate Proxy>' >> /etc/apt/apt.conf
RUN apt-get update
RUN echo "deb https://deb.nodesource.com/node_10.x xenial main" \n "deb-src https://deb.nodesource.com/node_10.x xenial main" > /etc/apt/sources.list.d/nodesource.list
RUN apt-get install -y curl
RUN apt-get install -y gnupg
RUN apt-get install -y build-essential
RUN apt-get install -y apt-transport-https
RUN curl -s --proxy <proxy> https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
RUN apt-get update
RUN apt-cache policy nodejs
RUN apt-get install -y nodejs
RUN node -v && npm -v
RUN apt-get install libaio1 # Async IO library used by Oracle client.
RUN apt-get install unzip # Unzip for Oracle client.
# Install Oracle instant client SDK.
# https://github.com/oracle/node-oracledb/blob/master/INSTALL.md
RUN mkdir /opt/oracle
RUN unzip instantclient-basic-linux.x64-19.5.0.0.0dbru.zip -d /opt/oracle
RUN unzip instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip -d /opt/oracle
RUN pwd && ls
RUN mv /opt/oracle/instantclient_19_5 /opt/oracle/instantclient
#RUN ln -s /opt/oracle/instantclient/libclntsh.so.19_5 /opt/oracle/instantclient/libclntsh.so
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient
Any ideas? If it is the ubuntu base image issue, and I need to add more tools on top of the base ubuntu image, what should I add on? if not, what the potential issue should be?
[I updated your post to format code; check out the changes.]
How do you know it hangs? Did you check the logs to see what output was displayed? Did you add some extra console.log() calls to triple check the code flow?
A general recommendation is to use async/await instead of callbacks, see examples like example.js.
Try putting SQL*Plus in the image and then see if you can use this to connect to the DB. It sounds like a networking issue.
To avoid hangs (and to get errors faster), you may want to create a /opt/oracle/instantclient/network/admin/sqlnet.ora file with a connection time out parameter like SQLNET.OUTBOUND_CONNECT_TIMEOUT, see https://oracle.github.io/node-oracledb/doc/api.html#connectionha
@cjbj Thanks for the response.
I added some console.logs inside the oracledb module code for debugging below, but it never get triggered in the Docker container.
Interesting thing is, if this is the network issue, then why the error response got returned, if I mocked the credentials, I could get the invalid usernam/password error msg back.
self._getConnection(connAttrs, function(err, connInst) {
console.log("**** Opening connection: " + JSON.stringify(connInst));
if (err) {
if (err.message.match(/DPI-1047/)) {
err.message += "\n" + nodbUtil.getInstallHelp();
}
getConnectionCb(err);
return;
}
getConnectionCb(null, connInst);
});
}
I changed the test code by using the await, it is same.
const oracledb = require('oracledb')
async function run() {
let pool;
console.log('Starting build the connection...');
try {
pool = await oracledb.createPool({
user: <username>,
password: <password>,
connectString: <connection info>
});
let connection;
try {
connection = await pool.getConnection();
console.log('Succeed connected..' + JSON.stringify(connection));
}catch(err){
throw(err)
}
}catch(err){
throw(err)
}
}
run()
or
const oracledb = require('oracledb')
async function run() {
let connection;
console.log('Starting build the connection...');
try {
connection = await oracledb.getConnection({
user: <username>,
password: <password>,
connectString: <connection info>
});
console.log('Succeed connected..' + JSON.stringify(connection));
}catch(err){
throw(err)
}
}
run()
See below picture, when I run the sample code above, it just hang and the console.logs
console.log('Succeed connected..' + JSON.stringify(connection));
did not be triggered.

I created the sqlnet.ora file with the SQLNET.OUTBOUND_CONNECT_TIMEOUT=10 added in, no effect.
I will try to install SQLPLUS and see what happens..
@cjbj Here is the update by using the sqlplus to connect the DB.
When I use wrong credentials in the connection string, it got the invalid username/password message. When I use the correct connection string, it just hang without any response.

When I use the same script to connect the DB in a different ubuntu 18.04 machine, it works.

Have you mapped any ports required? There are some notes in this OOW presentation (which is coming out as a 2 part blog post https://blogs.oracle.com/opal/docker-for-oracle-database-applications-in-nodejs-and-python-part-1)
What do you mean mapped any ports required? The oracle db server endpoint port is 1521 for sure.
Thanks for sharing such great blogs, I will definitely read them thoroughly. Unfortunately, the company recommends (I believe it is very close to mandatory) us to use Ubuntu as the OS of the Docker container, this make things a little bit hard as the Ubuntu base image is the minimum version which might not have all the necessary packages installed there.
This explains why the regular version of Ubuntu has no issue connecting to OracleDB but the minimum one has. I just do not know what the missing dependencies need to add on, there is very little information online regarding this specific issue. :(
My impression of why the other Ubuntu image is working is because it isn't being run in Docker. But this isn't really clear from your posts. The issue won't be packages. It will be ports and networks.
Regarding ports, are you using something like '-p 1521:1521' when you start the container?
I agree that this issue might down to ports and networks.
I am using the docker-compose to lunch the containers, and this container has another port mapping, -p 9004:9004, because this container isn't only for oracledb connection, it is a scheduling service container which we are using to run batch jobs and retrieve data from different data sources and oracleDB is just one of them.
I am in the docker container itself to test the connection, and your are right, the success Ubuntu image isn't in the Docker container and isn't minimal one.
However, I am able to connect to oracledb in another Docker container with the node as the base image which is on the Debian.
So I still suspect that the Ubuntu Docker image has some issues, just need to confirm, am going to post the question to their forum as well.
Please verify the depending libraries in the failed system are the same version as in the successful system. Please generate a sqlnet trace file for the failed case to see where client hangs.
@onmp Can you share steps on how to generate the sqlnet trace file? :)
In sqlnet.ora file at $ORACLE_HOME/network/admin, or $TNS_ADMIN/network/admin if you have set the environment variable $TNS_ADMIN, add the following statements: TRACE_LEVEL_CLIENT=16 TRACE_DIRECTORY_CLIENT=/tmp TRACE_UNIQUE_CLIENT=ON TRACE_TIMESTAMP_CLIENT=ON DIG_ADR_ENABLED=OFF
Please upload the trace file that ends with .trc.
@cjbj @onmp Thanks for your both help, no clue but seems the failed system is able to connect to Oracle DB now, No change from my side.
@wodeleeway thanks for the update. I'll close this issue now.