title: Nodejs microservice to SQL Server database connection timout
body: <p>I am using <a href="https://loopback.io/doc/en/lb3/" rel="nofollow noreferrer">loopback3</a> for creating Nodejs microservice.</p>
  <p>I have total 7 to 8 micro services. All the micro services connecting to different SQL Server databases running on same instance (192.168.20.25:1433). I am building docker images for the micro services and running them using Kubernetes Pods on openshift cluster.</p>
  <p>All of the micro services are connecting to  192.168.20.25:1433 SQL Server database properly.</p>
  <p>But one of the micro services is facing the database connection timeout issue. But same code when I run on a virtual machine using &quot;npm start&quot; command then it's able to connect to the same db.</p>
  <p>Difference here is I am running code with  docker images and kubernetes pods, it's giving DB connection timeout issue. And when I am running code without docker images and kubernetes pods as normal npm start command then it works.</p>
  <p>Any idea what could be the issue? Thanks in advance for help.</p>
  <p>Below is the error log:</p>
  <pre><code>loopback:connector:mssql Connection error:  ConnectionError: Failed to connect to 192.168.20.25:1433 in 15000ms
      at Connection.&lt;anonymous&gt; (/home/normaluser/node_modules/mssql/lib/tedious/connection-pool.js:68:17)
      at Object.onceWrapper (events.js:520:26)
      at Connection.emit (events.js:400:28)
      at Connection.connectTimeout (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/connection.js:1195:10)
      at Timeout._onTimeout (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/connection.js:1157:12)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7) {
    code: 'ETIMEOUT',
    originalError: ConnectionError: Failed to connect to 192.168.20.25:1433 in 15000ms
        at ConnectionError (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/errors.js:13:12)
        at Connection.connectTimeout (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/connection.js:1195:54)
        at Timeout._onTimeout (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/connection.js:1157:12)
        at listOnTimeout (internal/timers.js:557:17)
        at processTimers (internal/timers.js:500:7) {
      code: 'ETIMEOUT'
    }
  }
  2022-06-27T05:37:41.095Z loopback:datasource Connector is initialized for dataSource DB
  2022-06-27T05:37:41.095Z strong-globalize ~~~ lang = en a2487abefef4259c2131d96cdb8543b1 [&quot;ConnectionError: Failed to connect to 192.168.20.25:1433 in 15000ms&quot;] /home/normaluser/node_modules/strong-globalize/lib/globalize.js
  Connection fails: ConnectionError: Failed to connect to 192.168.20.25:1433 in 15000ms
  It will be retried for the next request.
  /home/normaluser/node_modules/mssql/lib/tedious/connection-pool.js:68
            err = new ConnectionError(err)
                  ^
  ConnectionError: Failed to connect to 192.168.20.25:1433 in 15000ms
      at Connection.&lt;anonymous&gt; (/home/normaluser/node_modules/mssql/lib/tedious/connection-pool.js:68:17)
      at Object.onceWrapper (events.js:520:26)
      at Connection.emit (events.js:400:28)
      at Connection.connectTimeout (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/connection.js:1195:10)
      at Timeout._onTimeout (/home/normaluser/node_modules/mssql/node_modules/tedious/lib/connection.js:1157:12)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! transaction-service@1.0.0 start: `node .`
  npm ERR! Exit status 1
  npm ERR! 
  npm ERR! Failed at the transaction-service@1.0.0 start script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  </code></pre>
  <p>dockerfile:</p>
  <pre><code>#For Linux Instances
  FROM node:14-alpine
  
  # Create normal user
  RUN adduser -D normaluser
  USER normaluser
  
  # Create app directory
  WORKDIR /home/normaluser
  
  # Install app dependencies
  # A wildcard is used to ensure both package.json AND package-lock.json are copied
  # where available (npm@5+)
  COPY package*.json ./
  
  # If you are building your code for production
  # RUN npm install --only=production
  RUN npm install 
  
  # Bundle app source
  COPY . .
  
  EXPOSE 3002
  #SET ENV To Production
  #ENV NODE_ENV=production
  
  CMD [ &quot;npm&quot;, &quot;start&quot; ]
  
  </code></pre>
  <p>kubernetes pod YAML file:</p>
  <pre><code>
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: xyz-transaction-dev
    namespace: xyz-dev
  spec:
    replicas: 1
    selector:
      matchLabels:
        name: xyz-transaction-dev
    template:
      metadata:
        labels:
          name: xyz-transaction-dev
      spec:
        containers:
          - name: xyz-transaction-dev
            image: &lt;image registry url&gt;:v1.63
            imagePullPolicy: Always
            envFrom:
              - secretRef:
                  name: transaction-secret
              - secretRef:
                  name: global-secret
       
            resources:
              requests:
                cpu: &quot;60m&quot;
                memory: &quot;150Mi&quot;
              limits:
                cpu: &quot;150m&quot;
                memory: &quot;250Mi&quot;
            ports:
              - containerPort: 3002
                protocal: TCP
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: transaction
    namespace: xyz-dev
  spec:
    ports:
      - port: 3002
        name: 3002-tcp
        protocal: TCP
        targetPort: 3002
    selector:
      name: xyz-transaction-dev
  
  </code></pre>