IBM / node-odbc

ODBC bindings for node
MIT License
143 stars 75 forks source link

[BUG] Container exits with status code 139 when calling stored procedure #388

Closed kansasturnpike closed 2 months ago

kansasturnpike commented 2 months ago

Describe your system

Describe the bug Multiple calls to callProcedure() within a short time (10 calls within 2secs) results in a segfault error:

PID 1 received SIGSEGV for address: 0x0
/app/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3206)[0x7ffffc6f1206]
/lib64/libc.so.6(+0x3e6f0)[0x7ffffed446f0]
/opt/ibm/iaccess/lib64/libcwbodbc.so(_ZN14STATEMENT_INFO10getColDataEmR11COLUMN_INFOljPcj+0x25f)[0x7ffffc1c045f]
/opt/ibm/iaccess/lib64/libcwbodbc.so(_ZN14STATEMENT_INFO15goOverBoundColsElb+0x9b)[0x7ffffc1c11fb]
/opt/ibm/iaccess/lib64/libcwbodbc.so(_ZN14STATEMENT_INFO7doFetchEjtlPmPt+0x273)[0x7ffffc1c17c3]
/opt/ibm/iaccess/lib64/libcwbodbc.so(SQLFetch+0xac)[0x7ffffc1a5f5c]
/lib64/libodbc.so.2(SQLFetch+0x11d)[0x7ffffc71ad0d]
/app/node_modules/odbc/lib/bindings/napi-v6/odbc.node(_Z15fetch_and_storeP13StatementDatabPb+0x51)[0x7ffffc46af21]
/app/node_modules/odbc/lib/bindings/napi-v6/odbc.node(_Z19fetch_all_and_storeP13StatementDatabPb+0x2d)[0x7ffffc46b6ed]
/app/node_modules/odbc/lib/bindings/napi-v6/odbc.node(_ZN24CallProcedureAsyncWorker7ExecuteEv+0x16f)[0x7ffffc47008f]
node(_ZZN4node14ThreadPoolWork12ScheduleWorkEvENUlP9uv_work_sE_4_FUNES2_+0x6e)[0x555555e3c4be]
node(+0x13d8522)[0x55555692c522]
/lib64/libc.so.6(+0x89c02)[0x7ffffed8fc02]
/lib64/libc.so.6(clone+0x44)[0x7ffffee13ed4]
PID 1 received SIGSEGV for address: 0x0

To Reproduce Steps to reproduce the behavior:

  1. Connect to database

    async connect(): Promise<Connection> {
    const config = this.configService.get<Db2Config>('db2Config')
    const poolConnection = await pool(db2Config: {
    connectionString: DRIVER=IBM i Access ODBC Driver; SYSTEM=${process.env.DB2_HOST}; UID=${process.env.DB2_USER}; PWD=${process.env.DB2_PASS}; CCSID=1208; naming=1; dbq=,${process.env.DB2_DATA}, ${process.env.DB2_OBJECTS}, ${process.env.JAVA};TRIMCHAR=1;,
    reuseConnections: true
    })
    return await poolConnection.connect()
    }
  2. Call Stored Procedure

    await this.db2.callProcedure(
    null,
    process.env.DB2_OBJECTS,
    procedure.name,
    Object.values(procedure.params)
    )
  3. Run 10+ requests within 1-2 seconds

Container error: container is terminated because of Error. It exited with exit code 139. It is not started and not ready. The container last terminated with exit code 139 because of Error.

Google search result description of issue:

When a container exits with status code 139, it's because it received a SIGSEGV signal. The operating system terminated the container's process to guard against a memory integrity violation. It's important to investigate what's causing the segmentation errors if your containers are terminating with code 139

According to this site: https://www.groundcover.com/kubernetes-troubleshooting/exit-code-139

Common Causes of Exit Code 139

Problem Description How to fix
Incompatible libraries Application is using a different version of a library than intended. Update configuration to point the right library version.
Coding errors Programming errors cause application to reference memory incorrectly. Debug the application to find the faulty code, then update it.
Hardware issues Incompatibility between memory subsystems and an application. Check physical memory for problems. Migrate to a different server if necessary.

IBM i Access ODBC Driver website: https://ibmi-oss-docs.readthedocs.io/en/latest/odbc/installation.html

Dockerfile

FROM registry.access.redhat.com/ubi9/nodejs-18:1-112.1720017853 as default
ENV TZ="America/Chicago"

USER 0

/etc/apt/sources.list.d/ibmi-acs-1.1.0.list
RUN curl https://public.dhe.ibm.com/software/ibmi/products/odbc/rpms/ibmi-acs.repo | tee /etc/yum.repos.d/ibmi-acs.repo

RUN dnf install --refresh ibm-iaccess -y
RUN dnf install unixODBC unixODBC-devel -y

RUN npm i -g yarn

RUN mkdir /app
RUN chown 1001:0 /app

USER 1001

# # Project files
WORKDIR /app
COPY . .
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
RUN yarn build

CMD [ "node", "dist/main" ]

##### references #####
# article: https://github.com/worksofliam/blog/issues/49
# odbc: https://github.com/markdirish/node-odbc#callprocedurecatalog-schema-name-parameters-callback
# driver ibm-iaccess download: https://ibmi-oss-docs.readthedocs.io/en/latest/odbc/installation.html#linux

# NOTE: When running on Mac using M2 (AMD64), make sure to specify --platform=linux/amd64 when building image
kansasturnpike commented 2 months ago

I was able to resolve the issue. It was related to returning a connection from the pool rather than the pool. Once I did that it was fine.