ibmdb / python-ibmdb

Automatically exported from code.google.com/p/ibm-db
Apache License 2.0
305 stars 191 forks source link

Floating point exception: 8 on macOS #502

Closed killuazhu closed 3 years ago

killuazhu commented 4 years ago

Hello,

I'm getting floating point exception when using python -c “ibm_db.connect” on macOS

When I’m running command below on macOS

python -c 'import ibm_db;conn_str="database=db;hostname=hostname;port=port;protocol=tcpip;uid=my_user;pwd=my_password;ConnectTimeout=5";c=ibm_db.connect(conn_str,"","");server=ibm_db.server_info(c);print(server.DBMS_VER);'

It will error out with Floating point exception: 8. Interesting though, if I launch a python REPL with python, then input the commands in previous string one line at a time, I can properly connect to the DB without getting any error.

I also don’t get the error when running same command on Linux env.

Env

killuazhu commented 4 years ago

I found a simpler way to reproduce, it does not even require valid connection string.

bash-3.2$ python --version
Python 3.8.2
bash-3.2$ python -c 'import ibm_db;ibm_db.connect("","","");'
Floating point exception: 8
imavo commented 4 years ago

no exception with Python 3.6.8 on Linux x64, and no exception on Python 2.7.12 , and none with Python 3.6.9
instead I get SQL1024N a database connection does not exist. (ibm_db 3.0.1) Maybe specific to Mac OS? Have you tried a CLI trace to see what's happening? Or run under a debugger to see where the exception happens?

killuazhu commented 4 years ago

@imavo thanks for confirming. That's inline with my comment in the description that "I also don’t get the error when running same command on Linux env."

Maybe specific to Mac OS?

That's what I experience. My teammate was also having the same issue on macOS.

Have you tried a CLI trace to see what's happening? Or run under a debugger to see where the exception happens?

Do you mind sharing how to do so with ibm-db? I would be interested to try it out.

imavo commented 4 years ago

Missed your remark that you already found it did not happen on Linux, apologies.

CLI tracing is a function of the IBM Db2 drivers (including the ODBC and CLI driver that gets pulled by default when you install ibm_db module). Refer to the Db2 online knowledge centre for instructions, or see many other issues in this github page where people ask the same question about tracing. Link to IBM docs is https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.admin.trb.doc/doc/c0008936.html

For debugging, you need a debugger tool (lldb, gdb, ...) for c/c++ applications, that works with mac os, and some developer skills. I don't use Mac so cannot be specific.

However, even without using any debugger, I suspect the Mac Os has saved a crash report or coredump somewhere, containing useful details, you might search for crash reports.

killuazhu commented 4 years ago

@imavo The crash report is a good pointer. I reproduced and able to grab a crash report from macOS console

Looks like it's crashing on 0 libdb2.dylib 0x0000000101c4580f ossGetCPUInfo + 319 ?

Process:               python3.8 [21883]
Path:                  /Users/USER/*/python3.8
Identifier:            python3.8
Version:               ???
Code Type:             X86-64 (Native)
Parent Process:        fish [8410]
Responsible:           iTerm2 [826]
User ID:               501

Date/Time:             2020-04-24 16:45:24.857 -0400
OS Version:            Mac OS X 10.15.4 (19E287)
Report Version:        12
Bridge OS Version:     3.0 (14Y908)
Anonymous UUID:        2E53C856-7BDF-A63E-8D49-9475FB4EFCDE

Sleep/Wake UUID:       DFBAE954-8805-40BF-9CEF-797CDCD3D1EF

Time Awake Since Boot: 220000 seconds
Time Since Wake:       35000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_ARITHMETIC (SIGFPE)
Exception Codes:       EXC_I386_DIV (divide by zero)
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Floating point exception: 8
Termination Reason:    Namespace SIGNAL, Code 0x8
Terminating Process:   exc handler [21883]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libdb2.dylib                    0x0000000101c4580f ossGetCPUInfo + 319
1   libdb2.dylib                    0x00000001021e542d sqloInitializeCPUBindingGlobals() + 285
2   libdb2.dylib                    0x00000001021e4bc0 sqloGetDb2Processors + 1952
3   libdb2.dylib                    0x00000001025a6a94 sqloInitializeLatchTuningInfo + 4164
4   libdb2.dylib                    0x0000000101ce5f4a sqlePrimitiveKRCBInitialization + 1738
5   libdb2.dylib                    0x00000001025f674d sqlo_create_init_app_data_preset + 13
6   libdb2.dylib                    0x0000000101cc5eff sqleInitApplicationEnvironment(int, unsigned int, unsigned int, sqlca*) + 8751
7   libdb2.dylib                    0x0000000101d12ecd sqleuApplicationInit + 909
8   libdb2.dylib                    0x0000000102079bd7 SQLAllocHandle + 5127
9   ibm_db.cpython-38-darwin.so     0x0000000101a73449 _python_ibm_db_connect_helper + 1033
10  python                          0x0000000101447b4a cfunction_call_varargs + 122
11  python                          0x0000000101447586 _PyObject_MakeTpCall + 374
12  python                          0x000000010152ec4c call_function + 652
13  python                          0x000000010152b34d _PyEval_EvalFrameDefault + 30253
14  python                          0x000000010152fcb3 _PyEval_EvalCodeWithName + 3459
15  python                          0x0000000101523c80 PyEval_EvalCode + 48
16  python                          0x0000000101576c03 PyRun_StringFlags + 259
17  python                          0x0000000101576ab5 PyRun_SimpleStringFlags + 69
18  python                          0x000000010159544a Py_RunMain + 506
19  python                          0x0000000101596086 pymain_main + 406
20  python                          0x00000001015960db Py_BytesMain + 43
21  libdyld.dylib                   0x00007fff70244cc9 start + 1

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x0000000000000000  rcx: 0x0000000000000000  rdx: 0x0000000000000000
  rdi: 0x00007ffeee7d6760  rsi: 0x00007ffeee7d65e8  rbp: 0x00007ffeee7d67d0  rsp: 0x00007ffeee7d6730
   r8: 0x0000000000000000   r9: 0x0000000000000000  r10: 0x0000000000000000  r11: 0x0000000000000000
  r12: 0x0000000000000000  r13: 0x00007ffeee7d67e8  r14: 0x0000000000000000  r15: 0x0000000000000000
  rip: 0x0000000101c4580f  rfl: 0x0000000000010246  cr2: 0x0000000101c456d0

Logical CPU:     2
Error Code:      0x00000000
Trap Number:     0

Binary Images:
       0x101424000 -        0x101679fff +python (0) <36D866C4-B3CC-38BC-9137-0EB16B139F76> /Users/USER/*/python
       0x1017b4000 -        0x1017bcffb +libintl.8.dylib (0) <9E94108B-5714-3275-90C8-EBE92F56C0CE> /usr/local/opt/gettext/lib/libintl.8.dylib
       0x101a66000 -        0x101a7afff +ibm_db.cpython-38-darwin.so (0) <52E6DE76-E117-3A08-A61A-CF68EC1AC55A> /Users/USER/*/ibm_db.cpython-38-darwin.so
       0x101a83000 -        0x10356cfef +libdb2.dylib (0) <BDA27A05-4DFF-3F00-817C-24699843EF29> /Users/USER/*/libdb2.dylib
       0x103a17000 -        0x103a20ffb +math.cpython-38-darwin.so (0) <7D0168D6-CC73-3FCE-8C3A-61AEA89D7B22> /Users/USER/*/math.cpython-38-darwin.so
       0x103a68000 -        0x103a77ff7 +_datetime.cpython-38-darwin.so (0) <4DD93F2E-7DE0-33B3-BBC5-7DAB0F015CF9> /Users/USER/*/_datetime.cpython-38-darwin.so
       0x10c6c3000 -        0x10c754eff  dyld (750.5) <1F893B81-89A5-3502-8510-95B97B9F730D> /usr/lib/dyld
    0x7fff3627a000 -     0x7fff366f9ffb  com.apple.CoreFoundation (6.9 - 1675.129) <9E632A1E-9622-33D6-BCCE-23AC16DAA6B7> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    0x7fff6cd54000 -     0x7fff6cd56ff7  libDiagnosticMessagesClient.dylib (112) <BE749883-9400-334A-8FBF-F3321CF205F5> /usr/lib/libDiagnosticMessagesClient.dylib
    0x7fff6d22a000 -     0x7fff6d22bfff  libSystem.B.dylib (1281.100.1) <DB8310F1-272D-3533-A840-3B390AF55C26> /usr/lib/libSystem.B.dylib
    0x7fff6d510000 -     0x7fff6d562fff  libc++.1.dylib (902.1) <08199809-33CA-321E-9B9D-FD5B2BC64580> /usr/lib/libc++.1.dylib
    0x7fff6d563000 -     0x7fff6d578ffb  libc++abi.dylib (902) <1C880020-396D-3F91-BE27-5A09A9239F68> /usr/lib/libc++abi.dylib
    0x7fff6d579000 -     0x7fff6d579fff  libcharset.1.dylib (59) <4E63BA25-04A3-329A-923D-251155C03F30> /usr/lib/libcharset.1.dylib
    0x7fff6dfe4000 -     0x7fff6dfe6fff  libfakelink.dylib (149.1) <B04F9A05-7E52-3382-9186-F603BE4BFBB2> /usr/lib/libfakelink.dylib
    0x7fff6e005000 -     0x7fff6e0f5fff  libiconv.2.dylib (59) <9458704B-A702-37CB-9707-66ABBB5DB71E> /usr/lib/libiconv.2.dylib
    0x7fff6e0f6000 -     0x7fff6e34dfff  libicucore.A.dylib (64260.0.1) <DCC4A4EE-32FD-350F-84D8-E857F2F29855> /usr/lib/libicucore.A.dylib
    0x7fff6f08a000 -     0x7fff6f0bdfde  libobjc.A.dylib (787.1) <20AC082F-2DB7-3974-A2D4-8C5E01787584> /usr/lib/libobjc.A.dylib
    0x7fff6f191000 -     0x7fff6f1a9fff  libresolv.9.dylib (67.40.1) <92A522F9-95E2-35EE-A8AD-FC8DEE6B2C1F> /usr/lib/libresolv.9.dylib
    0x7fff6f513000 -     0x7fff6f55dff7  libstdc++.6.dylib (104.1) <3779D567-DCA6-3175-AC9B-0A8293DA5E70> /usr/lib/libstdc++.6.dylib
    0x7fff6f766000 -     0x7fff6f778ff3  libz.1.dylib (76) <6A449C6A-DF88-36C1-8F2D-DB9A808263B5> /usr/lib/libz.1.dylib
    0x7fff70026000 -     0x7fff7002bff3  libcache.dylib (83) <5F90FFCE-403B-3724-991D-BA32401D99C5> /usr/lib/system/libcache.dylib
    0x7fff7002c000 -     0x7fff70037fff  libcommonCrypto.dylib (60165) <C7A5E3F7-1E5A-3785-875A-B6647082B614> /usr/lib/system/libcommonCrypto.dylib
    0x7fff70038000 -     0x7fff7003ffff  libcompiler_rt.dylib (101.2) <A517E149-2D25-3C04-BCEF-F69149C85B18> /usr/lib/system/libcompiler_rt.dylib
    0x7fff70040000 -     0x7fff70049ff7  libcopyfile.dylib (166.40.1) <1A5270B5-0D97-35DA-9296-4F4A428BC6A2> /usr/lib/system/libcopyfile.dylib
    0x7fff7004a000 -     0x7fff700dcfe3  libcorecrypto.dylib (866.100.30) <FCDEC0D1-8C30-3989-BDD1-996BBC715C29> /usr/lib/system/libcorecrypto.dylib
    0x7fff701e9000 -     0x7fff70229ff0  libdispatch.dylib (1173.100.2) <EB592997-B11C-3AB3-85B1-F725F3D0B412> /usr/lib/system/libdispatch.dylib
    0x7fff7022a000 -     0x7fff70260fff  libdyld.dylib (750.5) <D2A07EF5-A64B-3692-BE13-89DAA2EC5E80> /usr/lib/system/libdyld.dylib
    0x7fff70261000 -     0x7fff70261ffb  libkeymgr.dylib (30) <CC5A2B43-770B-3C6C-BA10-AA3A6B4A142D> /usr/lib/system/libkeymgr.dylib
    0x7fff7026f000 -     0x7fff7026fff7  liblaunch.dylib (1738.100.39) <A7FF7357-600F-3014-8C28-A4F367717E8D> /usr/lib/system/liblaunch.dylib
    0x7fff70270000 -     0x7fff70275ff7  libmacho.dylib (959.0.1) <D8FED478-25A2-3844-AE4B-A5C9F9827615> /usr/lib/system/libmacho.dylib
    0x7fff70276000 -     0x7fff70278ff3  libquarantine.dylib (110.40.3) <51E0304F-AB11-3BF7-99DC-BB916CC9088B> /usr/lib/system/libquarantine.dylib
    0x7fff70279000 -     0x7fff7027aff7  libremovefile.dylib (48) <078F29AB-26BA-3493-BCAA-E1E75A187521> /usr/lib/system/libremovefile.dylib
    0x7fff7027b000 -     0x7fff70292ff3  libsystem_asl.dylib (377.60.2) <0F1BAC19-2AE0-3F8E-9B90-AACF819B2BF7> /usr/lib/system/libsystem_asl.dylib
    0x7fff70293000 -     0x7fff70293ff7  libsystem_blocks.dylib (74) <32224AFF-C06F-3279-B753-097194EDEF49> /usr/lib/system/libsystem_blocks.dylib
    0x7fff70294000 -     0x7fff7031bfff  libsystem_c.dylib (1353.100.2) <4F5EED22-4D46-3F04-8C64-C492CDAD70EB> /usr/lib/system/libsystem_c.dylib
    0x7fff7031c000 -     0x7fff7031fffb  libsystem_configuration.dylib (1061.101.1) <2A2C778D-07EB-35C7-A954-8BF8FD74BD75> /usr/lib/system/libsystem_configuration.dylib
    0x7fff70320000 -     0x7fff70323fff  libsystem_coreservices.dylib (114) <FDA41CC4-170A-3D93-85BD-838A563B03C4> /usr/lib/system/libsystem_coreservices.dylib
    0x7fff70324000 -     0x7fff7032cfff  libsystem_darwin.dylib (1353.100.2) <B567B86D-8818-38A4-A861-03EB83B55867> /usr/lib/system/libsystem_darwin.dylib
    0x7fff7032d000 -     0x7fff70334fff  libsystem_dnssd.dylib (1096.100.3) <7C690DF5-E119-33FB-85CD-9EFC67A36E40> /usr/lib/system/libsystem_dnssd.dylib
    0x7fff70335000 -     0x7fff70336ffb  libsystem_featureflags.dylib (17) <415D83EF-084C-3485-B757-53001870EA94> /usr/lib/system/libsystem_featureflags.dylib
    0x7fff70337000 -     0x7fff70384ff7  libsystem_info.dylib (538) <17049D3F-C798-3651-B391-1551FC699D3E> /usr/lib/system/libsystem_info.dylib
    0x7fff70385000 -     0x7fff703b1ff7  libsystem_kernel.dylib (6153.101.6) <E76440E1-D1E8-3D9A-8B47-D01F554FF1C4> /usr/lib/system/libsystem_kernel.dylib
    0x7fff703b2000 -     0x7fff703f9fff  libsystem_m.dylib (3178) <74741FA8-5C29-3241-9046-4FC91C6A6D4A> /usr/lib/system/libsystem_m.dylib
    0x7fff703fa000 -     0x7fff70421fff  libsystem_malloc.dylib (283.100.5) <97833239-2F83-3AEB-A426-0593997C8A54> /usr/lib/system/libsystem_malloc.dylib
    0x7fff70422000 -     0x7fff7042fffb  libsystem_networkextension.dylib (1095.100.29) <C9E988B2-6A18-35C0-9577-63201E9D6018> /usr/lib/system/libsystem_networkextension.dylib
    0x7fff70430000 -     0x7fff70439ff7  libsystem_notify.dylib (241.100.2) <E405F84B-BD4F-3874-9755-CB3EC86E18D5> /usr/lib/system/libsystem_notify.dylib
    0x7fff7043a000 -     0x7fff70442fef  libsystem_platform.dylib (220.100.1) <6EF12F34-C33F-36BF-9A9A-2A35EA19EFE0> /usr/lib/system/libsystem_platform.dylib
    0x7fff70443000 -     0x7fff7044dfff  libsystem_pthread.dylib (416.100.3) <A8514582-E000-3854-911A-0A73D2C79600> /usr/lib/system/libsystem_pthread.dylib
    0x7fff7044e000 -     0x7fff70452ff3  libsystem_sandbox.dylib (1217.101.2) <E9D78CDE-FB67-32E7-BABC-9EFC23AA0DC6> /usr/lib/system/libsystem_sandbox.dylib
    0x7fff70453000 -     0x7fff70455fff  libsystem_secinit.dylib (62.100.2) <AAC639E5-7103-3366-A602-8FC6944E2C13> /usr/lib/system/libsystem_secinit.dylib
    0x7fff70456000 -     0x7fff7045dffb  libsystem_symptoms.dylib (1238.100.26) <487B92DE-45F9-39F9-A478-89BBD478157D> /usr/lib/system/libsystem_symptoms.dylib
    0x7fff7045e000 -     0x7fff70474ff2  libsystem_trace.dylib (1147.100.8) <BB90B1FD-8C09-3DF4-BD8B-9E4AEADFEA2B> /usr/lib/system/libsystem_trace.dylib
    0x7fff70476000 -     0x7fff7047bff7  libunwind.dylib (35.4) <CC87C836-BE9D-334E-A0E6-0297D52E9D73> /usr/lib/system/libunwind.dylib
    0x7fff7047c000 -     0x7fff704b1ffe  libxpc.dylib (1738.100.39) <32B0E31E-9DA3-328B-A962-BC9591B93537> /usr/lib/system/libxpc.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 20106797
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=432.5M resident=0K(0%) swapped_out_or_unallocated=432.5M(100%)
Writable regions: Total=91.4M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=91.4M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                    8K        1 
MALLOC                            72.5M       26 
MALLOC guard page                   16K        3 
MALLOC_LARGE (reserved)            640K        2         reserved VM address space (unallocated)
STACK GUARD                          4K        1 
Stack                             16.0M        1 
VM_ALLOCATE                       1792K        7 
__DATA                            6009K       57 
__DATA_CONST                        56K        6 
__LINKEDIT                       390.1M        8 
__OBJC_RO                         32.2M        1 
__OBJC_RW                         1892K        2 
__TEXT                            42.4M       54 
__UNICODE                          564K        1 
shared memory                       12K        3 
===========                     =======  ======= 
TOTAL                            564.0M      173 
TOTAL, minus reserved VM space   563.3M      173 
imavo commented 4 years ago

Looks like python ibm_db module calls SQLAllocHandle() , as its first CLI call in your case, and that is in libdb2 which is part of the Db2 CLI driver .

It would be useful if you could test the Db2 CLI driver without using python. You can do this with the command db2cli which is a program that is part of the Db2 CLI driver and lives in the clidriver/bin directory under your ibm_db installation location.

Example command line db2cli validate -dsn YOURALIAS -connect YOURUSER -passwd YOURPASSWD (where you already have your db2dsdriver.cfg file configured with the dsn and database connection details for your databases). You can read the IBM Db2 Knowledge Centre online (search for db2cli) to see all the details, and also the details of configuring db2dsdriver.cfg xml file for your environment.

The idea is that if you can get the same exception without using Python then the issue has nothing to do with ibm_db, and instead is an issue in the Db2 CLI driver on your environment.

killuazhu commented 4 years ago

@imavo I'm able to use db2cli to run some connection test as below, it did not run into exception though.

bash-3.2$ conn_str="DATABASE=${DB2_DB};HOSTNAME=${DB2_HOSTNAME};PORT=${DB2_PORT};PROTOCOL=TCPIP;UID=${DB2_UID};PWD=${DB2_PWD};Security=SSL;"
bash-3.2$ pip show ibm-db
Name: ibm-db
Version: 3.0.1
Summary: Python DBI driver for DB2 (LUW, zOS, i5) and IDS
Home-page: http://pypi.python.org/pypi/ibm_db/
Author: IBM Application Development Team
Author-email: opendev@us.ibm.com
License: Apache License 2.0
Location: /Users/killua/.pyenv/versions/3.8.2/lib/python3.8/site-packages
Requires:
Required-by: detect-secrets
bash-3.2$ pwd
/Users/killua/.pyenv/versions/3.8.2/lib/python3.8/site-packages/clidriver/bin
bash-3.2$ ./db2cli execsql -connstring ${conn_str} -inputsql /tmp/select_time.sql
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
> SELECT current timestamp, current member FROM sysibm.sysdummy1
FetchAll:  Columns: 2
  1 2
  2020-04-25 13:49:21.601572, 0
FetchAll: 1 rows fetched.
>
bash-3.2$ cat /tmp/select_time.sql
SELECT current timestamp, current member FROM sysibm.sysdummy1;

bash-3.2$ python -c "import ibm_db;conn_str=\"${conn_str}\";c=ibm_db.connect(conn_str,'','');server=ibm_db.server_info(c);print(server.DBMS_VER);"
Floating point exception: 8
imavo commented 4 years ago

You write that connecting works with python REPL, but not otherwise. Try to find what is different between these situations in terms of what components are being used, versions, libraries etc.

bimalkjha commented 3 years ago

@killuazhu Please let us know if you are still facing this problem. Thanks.

amukherjee28 commented 3 years ago

Hi @killuazhu

Can we close this issue?

killuazhu commented 3 years ago

We can close for now. We are not getting report of the issue recently. We can reopen if needed in the future. Thanks.