Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: V3.1.4 on z/OS abends S0C4 for function fetch_both() and returns a python UTF decode error for function field_name() #852

Closed
pjfarleyiii opened this issue May 22, 2023 · 63 comments

Comments

@pjfarleyiii
Copy link

pjfarleyiii commented May 22, 2023

The errors described in this issue are occurring on the IBM Zxplore open learning system for z/OS (anyone can register to join at Zxplore Learning System). I am not an admin of that system and have no access to any software on that system except what the IBM Zxplore admins provide. I have no authority to install or upgrade software on that system, only the IBM Zxplore admins have that authority.

Please advise what I can communicate to the Zxplore admins to get assistance in resolving these issues.

  • Operating System Name: z/OS V2.4

  • db2level output from clidriver if in use:

  • Target Db2 Server Version: V12

  • Python Version: Python 3.9.2

  • ibm_db version: 3.1.4

  • For non-Windows, output of below commands:
    uname OS/390
    uname -m 3931

  • Value of below environment variables if set:
    IBM_DB_HOME: DSNC10
    PATH: /usr/lpp/IBM/cvg/go/bin:/usr/lpp/IBM/cyp/v3r9/pyz/bin:/usr/lpp/IBM/zoautil/bin:/usr/lpp/db2c10/jdbc/bin:/bin:/z/bin:.:/usr/lpp/java/J8.0_64/bin:/usr/lpp/zLiberty/V8R5/wlp/bin:/z/z02446/bin:/z/rocket/tools/bin:/usr/lpp/ported/bin:/usr/lpp/IBM/cnj/v18r0/IBM/node-latest-os390-s390x/bin:/usr/lpp/IBM/cnj/v18r0/njsc/bin:/global/node/bin:/usr/lpp/mqm/V9R1M1/web/bin:/usr/lpp/IBM/cobol/igyv6r4/bin
    LIB/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH: /usr/lpp/db2c10/jdbc/lib

  • Test script to reproduce the problem.

  • For fetch_both() attached script db_fetch_both_err.py as text file

  • For field_name() attached script db_fetch_name_err.py as text file

db_fetch_both_err.py.txt

db_fetch_name_err.py.txt

Steps to Reproduce:

  1. python3.9 db_fetch_both_err.py
  2. python3.9 db_fetch_name_err.py

Output from test scripts for functions fetch_both() and field_name() (Zxplore userid masked) pasted below. Also uploaded here is the CEEDUMP output from the S0C4 abend as a zip fille.

CEEDUMP.20230528.175140.16842984.zip

/z/zxxxxx > python3.9 db_fetch_both_err.py
Test start fetch_both
Connection done
exec_immediate done
CEE3204S The system detected a protection exception (System Completion Code=0C4).
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C3A89B4 at entry offset +0000000000000074 at address 000000001C3A89B4.
Segmentation fault

/z/zxxxxx > python3.9 db_fetch_name_err.py
Test start field_name
Connection done
exec_immediate done
first fetch done
row 1 returned 3 columns: Traceback (most recent call last):
  File "/z/zxxxxx/db_fetch_name_err.py", line 41, in <module>
    colname = ibm_db.field_name(stmt, _i)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 0: invalid continuation byte
@pjfarleyiii pjfarleyiii changed the title V3.1.4 on z/OS abends S0C4 for function fetch_both and returns a python UTF decode error for function field name V3.1.4 on z/OS abends S0C4 for function fetch_both() and returns a python UTF decode error for function field_name() May 23, 2023
@pjfarleyiii pjfarleyiii changed the title V3.1.4 on z/OS abends S0C4 for function fetch_both() and returns a python UTF decode error for function field_name() Bug Report: V3.1.4 on z/OS abends S0C4 for function fetch_both() and returns a python UTF decode error for function field_name() May 23, 2023
@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 3, 2023

Has anyone had the time yet to review these errors enough to know if they are environmental to the Zxplore system or actual ibmdb issues? Would appreciate knowing if there is any further information I could provide to assist with analysis and remediation.

@Earammak
Copy link
Collaborator

Earammak commented Jun 5, 2023

@pjfarleyiii I tried on my local machine and i didn't face any problem. Looks like issue is because of encoding. Can you please check what is the encoding you have.
Thanks

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 13, 2023

I am not sure which encoding the DB2 subsystem is using, but the general encoding I use on the Zxplore z/OS system is "IBM-1047" or in python "cp1047".

Both of the test scripts attached to this report are stored in the Zxplore USS file system as IBM-1047.

If you can tell me how to query it I will try to find out what the Zxplore DB2 subsystem is using by default, but I am kind of assuming it is probably code page 037.

@pjfarleyiii
Copy link
Author

I found out how to display the CCSID's in use by DB2 at the Zxplore site. SPUFI output from that site follows.

   SELECT GETVARIABLE('SYSIBM.SYSTEM_ASCII_CCSID')   ASCII_CCSID                                   
        , GETVARIABLE('SYSIBM.SYSTEM_EBCDIC_CCSID')  EBCDIC_CCSID                                  
        , GETVARIABLE('SYSIBM.SYSTEM_UNICODE_CCSID') UNICODE_CCSID                                 
    FROM SYSIBM.SYSDUMMY1                                                                          
   ;                                                                                               
---------+---------+---------+---------+---------+---------+---------+---------+---------+---------
ASCII_CCSID                                                                       EBCDIC_CCSID     
---------+---------+---------+---------+---------+---------+---------+---------+---------+---------
819,65534,65534                                                                   1047,65534,65534 
                  
------+---------+-
 UNICODE_CCSID    
------+---------+-
 367,1208,1200    
                  
DSNE610I NUMBER OF ROWS DISPLAYED IS 1                                                             

@Earammak
Copy link
Collaborator

@pjfarleyiii, I hope now are you able to run your test scripts correctly.
To check the existing file setting you can check from:
ls -aLT
Please refer this page to know about setting of change file tag information.

Please let us know if you need any further help.

Thanks

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 16, 2023

@Earammak I do know about file tagging and my scripts are tagged IBM1047. They fail as coded and tagged and described in detail in my first post. What can I do to help your team to fix these errors? The fetch_both script fails at the fetch_both function and the fetch_name script fails at the fetch_name function, and there is no encoding used to call those functions.

/z/z99999 > ls -laT db*.py
t IBM-1047    T=on  -rw-r--r--   1 Z02446   IPGROUP     1428 Mar  3 18:44 db_fetch_both_err.py
t IBM-1047    T=on  -rw-r--r--   1 Z02446   IPGROUP     1918 May 22 18:11 db_fetch_name_err.py

@Earammak
Copy link
Collaborator

@pjfarleyiii, I'm able to run in my environment. I used the same python script as your shared.
bash-4.3$ ls -laT fetch_both_err.py
t IBM-1047 T=on -rw-r--r-- 1 TS3596 PDUSER 1306 Jun 16 05:22 fetch_both_err.py
bash-4.3$ ls -laT fetch_name_error_852.py
t IBM-1047 T=on -rw-r--r-- 1 TS3596 PDUSER 1821 Jun 16 05:18 fetch_name_error_852.py
bash-4.3$ python3 --version
Python 3.9.5
bash-4.3$ uname -a
OS/390 RS25 28.00 04 3931
bash-4.3$ python3 fetch_both_err.py
Test start fetch_both
Connection done
exec_immediate done
first fetch done
Test end fetch_tuple
bash-4.3$ python3 fetch_name_error_852.py
Test start field_name
Connection done
exec_immediate done
first fetch done
Test end field_name
bash-4.3$
fetch_both_err.py.txt
fetch_name_error_852.py.txt

Please let me know if there is any discrepancy in my script.

Thanks

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 16, 2023

@Earammak the script outputs you got are not correct, even though they did not get any error. The "fetch_name" script is supposed to print the number of columns returned for each row and the names returned by the "fetch_name()" function for each column of each row. Your execution printed nothing, as if your DB2 data table is empty. Please try it with a DB2 table that contains some data and see what you get.

The same is true for the "fetch_both" script, if the DB2 table is not empty it should print the row number of each row returned by the "fetch_both()" function. Again, please try that script with a DB2 table that has some data in it and see what you get.

Here are modified copies of the test scripts that use table SYSIBM.SYSCOLUMNS, which should generate LOTS of output if the fetch_both() and fetch_name() functions are operating correctly. On the Zxplore system there are over 6400 rows in table SYSCOLUMNS, your system may have more or less rows. I found a set of WHERE conditions that will reduce the output to a reasonable size, as follows:

sql_stmt = "SELECT * FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = 'SYSCOLUMNS' AND TBCREATOR = 'SYSIBM' ORDER BY COLNO;"

db_fetch_both_err-2.py.txt

db_fetch_name_err-2.py.txt

db_fetch_tuple_no-err-2.py.txt

Please try these scripts on your system and let me know what you see. The new script db_fetch_tuple_no-err-2.py gets no error on the Zxplore system and prints 42 rows of output. It only uses the fetch_tuple() function, with which I have had no problems at all. If the other fetch functions are operating correctly their results should generate a similar output volume as the fetch_tuple version.

P.S. - The modified uploaded scripts above are encoded as ISO8859-1, not IBM1047. The originals on the USS file system are encoded as IBM1047.

@Earammak
Copy link
Collaborator

@pjfarleyiii, Find the below logs for the above-mentioned scripts.
issue_852_logs.zip

I'm able to run them successfully, and don't see any problem.
Can you please share here the issue you are facing here for your latest scripts.

Thanks

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 22, 2023

I do see that your system runs the scripts without any errors, and the output is correct for what is coded.

See my original report at the top. The "fetch_both" script abends at the first call to the "fetch_both()" function with S0C4 (addressing exception) in something called "TOROLABA" somewhere deep inside of the python runtime code. The "fetch_name" script ends with a decoding error at the first call to the "fetch_name()" function. I have generated the error output pasted below using both of the modified scripts.

These errors are consistent and repeatable - I get an S0C4 abend any time I use the "fetch_both()" function and a decoding error any time I use the "fetch_name()" function, no matter which DB2 table is referenced in the SELECT statement.

This is all happening on the IBM Zxplore z/OS system, not on a personal z/OS system of my own. I would appreciate any pointers you can provide for me to get more information than the dump I provided in my original report to help you to resolve these errors, or what I need to ask the Zxplore administrators to do that would help you to resolve them.

/z/z99999 > python3.9 db_fetch_name_err-2.py
Test start field_name
Connection done
exec_immediate done
first fetch done
row 1 returned 42 columns: Traceback (most recent call last):
  File "/z/z99999/db_fetch_name_err-2.py", line 35, in <module>
    colname = ibm_db.field_name(stmt, _i).decode("IBM1047")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 0: invalid continuation byte
/z/z99999 > python3.9 db_fetch_both_err-2.py
Test start fetch_both
Connection done
exec_immediate done
CEE3204S The system detected a protection exception (System Completion Code=0C4).
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C3A79B4 at entry offset 
+0000000000000074 at address 000000001C3A79B4.
Segmentation fault

@Earammak
Copy link
Collaborator

@pjfarleyiii Since you are observing this problem only on IBM Zxplore z/OS system and it is working on your local system.
Please check with IBM Zxplore z/OS system administrator on this issue that how we can resolve it.

Thanks

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 23, 2023

@Earammak You have it all wrong. I have NO LOCAL SYSTEM to run these scripts on I ONLY HAVE ZXPLORE!!!

WHAT CAN I DO TO GET MORE INFORMATION FOR YOU TO BE ABLE TO SOLVE THE ISSUE I SEE ON ZXPLORE?

The Zxplore admins have said they will cooperate to help me solve the problem, but I have to know what to ask them to do or what I have to do to give you the information you need to solve the problem. I sent you a dump, is that not enough information? What more do you need to solve the issue?

Please help me solve this issue.

[Edit]: Do the Zxplore admins have to open a support ticket with IBM or with you to get help to solve the problem?

@jthyssenrocket
Copy link

@pjfarleyiii

Was a SVC dump taken? If yes, can we get that, please? If no, can you set a SLIP for the S0C4 and capture a dump for us, please?

@pjfarleyiii
Copy link
Author

I cannot do that (I do not have the privileges needed), but I can ask the Zxplore sysadmin to set a SLIP and capture the dump for you. I can create the S0C4 on demand, so it should not take too long to get it. I will post it in a zip file when I have received it from the Zxplore team.

@jthyssenrocket
Copy link

Thanks! Do you know if the Zxplore team have plans to upgrade Python, as v3.9.2 is ~2 years old?

@pjfarleyiii
Copy link
Author

As I understand it from the Zxplore admins, it isn't entirely up to them - they use some "common" base system generated by some other IBM group (possibly WAZI?) and have to wait for that "common" base to be updated, they aren't always allowed to do upgrades on their own.

Meanwhile I am still waiting on a response to my request to set up a SLIP trap. As this python package isn't on their "we will positively support this" list, it may take a bit longer to get the dump. They did say they would try to help, but we have to depend on their availability to coordinate with me to get the dump, and there are time zone issues. I think my main contact is on Zulu time (UTC 0 offset) and I am UTC -4 (EDT).

@jthyssenrocket
Copy link

They are likely using the IBM ADCD distribution also used by other IBM solutions.
The latest release of ADCD is from May 2023, is built on RSU2303 and contains IBM Python 3.11.0.

If you can find HLQ ADCD in ISPF 3.4 you can determine the ADCD build from the second LQ. For example, the existence of ADCD.Z25D suggests it is the May 2023 distribution mentioned above.

Can you also confirm you're running on real hardware? I see machine type 3931 from uname, so likely a z16? The ADCD distribution is often used by emulated environments which have machine types 1090-1092.

The reason why I am asking is that I had another customer report a similar issue a while ago. They opened a support case with IBM Open Enterprise Python support, but the issue was never diagnosed as a refresh of their system to latest maintenance resolved the issue.

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jun 27, 2023

Yes, I believe they are running on a real z16, there was a hardware upgrade last month or the month before where they said they were going to a z16. No datasets under HLQ ADCD though.

By the way, would a SYSMDUMP file be as helpful as an SVC dump? I believe I can replicate the problem running the python3 script under BPXBATSL, and I can run that and generate the SYSMDUMP myself without any help form the admins.

[Edit] I tried to set up a job to capture a SYSMDUMP, but it does not do that, only generates CEEDUMP in my $HOME directory even when I override LE option TERMTHDACT to UAIMM. It does not work at all using BPXBATSL (/bin/login fails then) and BPXBATCH runs the shell in another address space. Will have to wait for the SLIP to get set up by the admins.

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Jul 1, 2023

Progress report: The Zxplore admins set up a SLIP as requested and I generated the S0C4 twice, but the SLIP did not fire yet.

I will continue to work with the Zxplore admins to get the dump generated from the SLIP and post here again when we have it.

@pjfarleyiii
Copy link
Author

Progress report: Unfortunately no more progress as yet. Still trying to get the repeatable S0C4 to trigger the SLIP. Administrators have been busy with other Zxplore issues, but I hope to have something available soon.

@denisgaebler
Copy link

Maybe its a similar issue, but any ideas why running on z/OS (printing ibm_db.conn_errormsg() ) would create a conversion error:

Traceback (most recent call last):
  File "/u/myid/python/testdb2.py", line 20, in <module>
    print( ibm_db.conn_errormsg() )
           ^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

And given the error reported above also occurs at conversion, is there a chance that something returned by the odbc driver is EBCDIC and as such not converted correctly? 0xe4 is 'ä' but I recall from using 1047 codepage at 3270 terminals that could be a bracket such as [] or {} displayed as 'ä'.

It could be environmental, wouldn't be the first time that anything else than cp037 would not work. Any environment variable or odbc setting I can look at or try to get rid of the conversion error?

It would be awkward, if one had to do ibm_db.conn_errormsg().decode(???) to get rid of the error.

@pjfarleyiii
Copy link
Author

@denisgaebler I had that same problem when first trying to issue an "exec_immediate()" to DB2. Below is what I had to code to see the error message from the failed operation. Part of the error message seems to be encoded in UTF-8, part seems to be encoded in IBM-1047. Perhaps something similar will work for a connect error for you.

    try:
        stmt = ibm_db.exec_immediate(conn,sql_stmtz)
    except:
        print("exec_immediate failed:")
        errmsg = str(ibm_db.stmt_errormsg().encode("ISO8859-1").decode("IBM1047"))
        errmsg = str(errmsg[:-13]) + str(errmsg[-13:].encode("IBM1047").decode("utf-8"))
        print(errmsg)
    else:
        print("exec_immediate done")

@daveyc
Copy link

daveyc commented Jul 17, 2023

@pjfarleyiii previously opened a ticket for pyzfile related to encoding issues on Z Xplore. It was bizarre as the encoding was performed in the Python runtime. I wasn't able to recreate the problem on local systems. This leads me to form the opinion with a high degree of probability that Python 3.9.2 on Z Xplore is broken. At the very least Python on Z Xplore should be upgraded to v3.9.16 PH53440 for there to be any point in continuing to investigate this issue. If we get a dump all that will do is confirm that the ABEND0C4 is caused by bad encoding.

@pjfarleyiii
Copy link
Author

@daveyc, As I responded to you on IBM-MAIN, IMHO it is not a useless exercise to nail down the root cause of these errors. If that root cause turns out to be a broken python version on the Zxplore system, that provides us with proof to goad the Zxplore admins to make a request that their version of python be upgraded. As far as I am aware, they do not actually completely control the contents and versions of products on the system they are using to reach out to those who wish to learn more about the z/OS environment and quirks. Their mandate is to teach and help people learn. My quest here is to make a useful product (ibmdb) work in that teaching environment for my own learning benefit and the benefit to other students seeking to learn there.

@daveyc
Copy link

daveyc commented Jul 17, 2023

@pjfarleyiii I think we should close this issue. Firstly, and most importantly, Python 3.9.2 is no longer available so we can't test it at Rocket. I'm also dubious about the Python distribution on the Z XPlore system. The traceback contains path names such as TOROLABA (Toronto Laboratories) that would suggest this may be beta code.

    6     PyObject_Hash                                                                                                             
                      TOROLABA:./Objects/object.c                         /VERSYSB/usr/lpp/IBM/cyp/v3r9/pyz/lib/libpython3.9.so     
    7     PyDict_SetItem                                                                                                          

My quest here is to make a useful product (ibmdb) work in that teaching environment for my own learning benefit and the benefit to other students seeking to learn there.

100%. But there is nothing the maintainers of this repo can do for an unsupported and broken Python.

@Earammak
Copy link
Collaborator

Earammak commented Aug 1, 2023

@pjfarleyiii Can you please provide update on this?

@bimalkjha
Copy link
Member

@daveyc Another user hit the similar problem. Detail is as below:

Message without dump:
CEE3204S The system detected a protection exception (System Completion Code=0C4)
.
         From compile unit TOROLABA:./Objects/typeobject.c at entry point PyType_Ready@AF337_43 at 
statement 6365 at compile unit offset +00000000232109EE at entry offset +000000000000001E at address 00000000232109EE.
[1] + Done(139) python odbc.fetcheboth.py
  50662733      Segmentation violation  /usr/bin/python  

Requested system dump to be attached.

The python appears to fail on ibm_db.fetch_both(stmt)
although when I replace it with ibm_db.fetch_tuple(stmt) the program works.

Environment
z/OS 2.5
DB2 z 12 Function Level 500
Python 3.10.9
ibm_db 3.1.4

Python script is encoded with cp1047 and terminal set to IBM-1047.

They have shared the SVCDUMP files that you can access from ftp2.rocketsoftware.com by searching TS013773510. Please download the dump and have a look into it. Thanks.

@pjfarleyiii
Copy link
Author

@Earammak , my status is that I am still awaiting a response from the Zxplore admins about whether the SLIP and the SVCDUMP DASD space are available and active. I have also tried generating the dump using

export _CEE_RUNOPTS='FILETAG(AUTOCVT,AUTOTAG) TRAP(OFF,NOSPIE) TER(UAIMM)'

but I have yet to see an SVCDUMP get created from the abend process. I am afraid this issue is just not very high on the list of things the Zxplore admins are concerned with.

If the other dump that was submitted is not sufficient to resolve the issue I can continue to try to get an SVCDUMP from Zxplore. Please keep me posted on whether or not I should continue to try to get this dump.

@jthyssenrocket
Copy link

jthyssenrocket commented Aug 9, 2023

@pjfarleyiii

Can you add the following to the odbc.ini file:

DIAGTRACE=1
DIAGTRACE_NO_WRAP=0
DIAGTRACE_BUFFER_SIZE=2000000

If you're not authorized to update /etc/odbc.ini, you can copy the file to your local directory and make the changes there. Make sure to change the environment variable DSNAOINI accordingly.

Then rerun the python program. This will produce a file named "DD:DSNAOTRC" in the current directory (yes, it has a weird name).

Then format the trace as follows:

cp "//'DSNC10.SDSNLOAD(DSNAO64T)'" ./dsnao64t
chmod +x ./dsnao64t
./dsnao64t fmt DD\:DSNAOTRC trace.txt

and upload the trace.txt file here.

@jthyssenrocket
Copy link

jthyssenrocket commented Aug 9, 2023

Please also post the output of:

set |grep BPX
set |grep CEE
set |grep STEPLIB
set |grep TAG
set |grep DSNAOINI

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 9, 2023

@jthyssenrocket , here are the requested "set | grep" results, working on the rerun with diagnostics next.

/z/z99999 > set |grep BPX
_BPXK_AUTOCVT=ON
/z/z99999 > set |grep CEE
STEPLIB=DSNC10.DBCG.SDSNEXIT:DSNC10.SDSNLOAD:DSNC10.SDSNLOD2:CEE.SCEERUN:IGY640.SIGYCOMP
_CEE_RUNOPTS='FILETAG(AUTOCVT,AUTOTAG) TERMTHDACT(UADUMP) ABTERMENC(ABEND)'
_LD_SYSLIB='//'\''CEE.SCEELKEX'\''://'\''CEE.SCEELKED'\''://'\''SYS1.CSSLIB'\''://'\''CBC.SCCNOBJ'\'''
/z/z99999 > set |grep STEPLIB
STEPLIB=DSNC10.DBCG.SDSNEXIT:DSNC10.SDSNLOAD:DSNC10.SDSNLOD2:CEE.SCEERUN:IGY640.SIGYCOMP
/z/z99999 > set |grep TAG
_CEE_RUNOPTS='FILETAG(AUTOCVT,AUTOTAG) TERMTHDACT(UADUMP) ABTERMENC(ABEND)'
_TAG_REDIR_ERR=txt
_TAG_REDIR_IN=txt
_TAG_REDIR_OUT=txt
/z/z99999 > set |grep DSNAOINI
DSNAOINI=/etc/odbc.ini

@pjfarleyiii
Copy link
Author

@jthyssenrocket the DIAG entries you requested were put into private copy of the /etc/odbc.ini file in the [COMMON] section and the python script was rerun as pasted below.

$HOME/.db2/odbc.ini:

; This is a comment line...
; Example COMMON stanza
[COMMON]
MVSDEFAULTSSID=DBCG
CONNECTTYPE=1
MULTICONTEXT=2
CURRENTAPPENSCH=ASCII
FLOAT=IEEE
DIAGTRACE=1
DIAGTRACE_NO_WRAP=0
DIAGTRACE_BUFFER_SIZE=2000000
[DBCG]
AUTOCOMMIT=1
MVSATTACHTYPE=CAF
PLANNAME=DSNACLI
/z/z02446 > export DSNAOINI=$HOME/.db2/odbc.ini  
/z/z02446 > export _CEE_RUNOPTS='FILETAG(AUTOCVT,AUTOTAG) TER(UADUMP) DYNDUMP(*USERID.CEEDUMP,DYNAMIC,TDUMP)'
/z/z02446 > python3 db_fetch_both_err-2.py
Test start fetch_both
Connection done
exec_immediate done
CEE3204S The system detected a protection exception (System Completion Code=0C4).
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset 
+0000000000000074 at address 000000001C4A79B4.
Killed

No file named "DD:DSNAOTRC" was created, but I did get a SYMDUMP-format CEEDUMP in the MVS dataset area named "Z99999.CEEDUMP.D221.T1030416.P00103DC" due to the _CEE_RUNOPTS options @daveyc suggested.

There is no executable named DSNAO64T in this system's DSNC10.SDSNLOAD, but there is a module named DSNOATRC. Should I look up how to run DSNOATRC in JCL and feed it the CEEDUMP as input?

@jthyssenrocket
Copy link

jthyssenrocket commented Aug 9, 2023

Sorry, my mistake: DSNAO64T is in SDSNLOD2 (not SDSNLOAD). However, we need the DD:DSNAOTRC file first.

There is an alternative set of instructions here:
https://www.ibm.com/docs/en/db2-for-zos/12?topic=odt-capturing-odbc-diagnostic-trace-information-in-zos-unix-environment
but it does not work in my environment.

If it doesn't work for you, I'll need some help from IBM Db2 ODBC dev to get the ODBC diag trace captured, as it contains information about the options used including application encoding scheme.

@jthyssenrocket
Copy link

The alternative instructions actually works for me from TSO OMVS, but not from a putty ssh session.

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 9, 2023

I will try the alternative instructions from a USS login and reply back. I am assuming that DSNAO64T is what I should use for this test, correct?

I created a Rexx script to allocate files including DSNAOTRC and a shell script to run the "dsn" commands and the python script. I allocated a userid.DIAGTRC file under my TSO ID defined as FB80 as documented in that IBM doc link you posted. Zxplore SMS rules for "students" on the site prevent us from creating or writing large sequential files though, so the allocated file may not be large enough to hold a lot of data. I can inquire of the admins if they can permit me an SMS exception that would allow a larger file to be created for the DIAGTRC output.

A file named "DD:DSNAOTRC" does seem to be created in my USS $HOME directory, but it is zero bytes long. The userid.DIAGTRC file I allocated is also empty after all of my attempts.

I also tried the shell script from OMVS as well, but same results as other tries. Output from OMVS attempt pasted below.

Following are the EXEC and shell script contents and the STDERR output from running them from TSO Option 6 as "EXEC (ODBCTEST) EXEC".

I even tried running BPXBATCH of the shell script in a batch job with REGION=500M, but the results were the same, "Not enough memory" error in STDERR.

userid.EXEC(ODBCTEST):

/* Rexx */                                                             
"Allocate File(STDOUT) Path('/z/z99999/odbc.stdout') REUSE" ,          
 "Pathopts(OWRONLY,OCREAT,OTRUNC) Pathmode(SIRWXU) Pathdisp(KEEP KEEP)"
"Allocate File(STDERR) Path('/z/z99999/odbc.stderr') REUSE" ,          
 "Pathopts(OWRONLY,OCREAT,OTRUNC) Pathmode(SIRWXU) Pathdisp(KEEP KEEP)"
"Allocate File(DSNAOTRC) da('Z99999.DIAGTRC') SHR REUSE"               
                                                                       
"BPXBATCH SH /z/z99999/odbctest.sh"                                    
                                                                       
"Free File(DSNAOTRC)"                                                  
"Free File(STDERR)"                                                    
"Free File(STDOUT)"                                                    

/z/z99999/odbctest.sh:

. /etc/profile 2> /dev/null
export _BPX_SHAREAS=YES
export DSNAOINI=/z/z99999/.db2/odbc.ini
./dsnao64t on
python3 db_fetch_both_err-2.py
./dsnao64t fmt DD\:DSNAOTRC trace.txt
./dsnao64t off

/z/z99999/odbc.stderr:

Trace is turned on
CEE3204S The system detected a protection exception (System Completion Code=0C4).
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset 
+0000000000000074 at address 000000001C4A79B4.
/z/z02446/odbctest.sh: line 4: 83952381 Segmentation fault      python3 db_fetch_both_err-2.py
Not enough memory to hold the trace.
Trace is already off; no action was taken.

OMVS Output:

/z/z99999 > ./odbctest.sh                                                                                                                                       
Trace is turned on                                                                                                                                              
Test start fetch_both                                                                                                                                           
Connection done                                                                                                                                                 
exec_immediate done                                                                                                                                             
CEE3204S The system detected a protection exception (System Completion Code=0C4).                                                                               
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset +0
000000000000074 at address 000000001C4A79B4.                                                                                                                    
./odbctest.sh: line 4: 83951888 Segmentation fault      python3 db_fetch_both_err-2.py                                                                          
Not enough memory to hold the trace.                                                                                                                            
Trace is already off; no action was taken.                                                                                                                      

@jthyssenrocket
Copy link

Sorry, if it wasn't clear: there are two alternative ways to collect the trace

Option 1: add the DIAG* keywords and optionally allocate DD DSNAOTRC file. It should be written during processing.
I connect to USS using ssh, and when running the python program it just write a file named DD:DSNAOTRC (I don't explicitly allocate it).

export DSNAOINI=/path/to/odbc_with_diagtrace.ini
python ...
./dsnao64t fmt DD\:DSNAOTRC dsnaotrc.txt   # format the trace 

Option 2: remove the DIAG* keywords, and use dsnao64t:

# odbc.ini without DIAG* keywords
export DSNAOINI=/path/to/odbc_without_diagtrace.ini
./dsnao64t on
python ... 
./dsnao64t dmp dmp.trc               # this should write a dmp.trc file
./dsnao64t fmt dmp.trc dmp.txt    # this should format the trace into a text file 

The error message "Not enough memory to hold the trace." suggests that your TSO region size (or imposed OMVS limits) is too small.

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 10, 2023

OK, I tried option 2 from a USS ssh login, results pasted below. I will try from an OMVS shell in TSO but I suspect the REGION for TSO is smaller than the USS limit on this "student" system.

/z/z99999 > ./dsnao64t on
Trace is turned on
/z/z99999 > python3 db_fetch_both_err-2.py
Test start fetch_both
Connection done
exec_immediate done
CEE3204S The system detected a protection exception (System Completion Code=0C4).
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset +0000000000000074 at address 000000001C4A79B4.
Segmentation fault
/z/z99999 > ./dsnao64t dmp odbc-dump.trc
Could not close odbc-dump.trc.
/z/z99999 > ./dsnao64t fmt odbc-dump.trc odbc-dump.txt
Not enough memory to hold the trace.
/z/z99999 > ls -la odbc-*.*
-rw-r--r--   1 Z99999   IPGROUP        0 Aug 10 11:28 odbc-dump.trc
/z/z99999 > ls -la DD*                                           
-rw-r--r--   1 Z99999   IPGROUP        0 Aug  9 17:24 DD:DSNAOTRC

Same results for both options from an OMVS shell in TSO logged on with Size ===> 512000 in the logon screen.

./dsnao64t on
/z/z99999 > ./dsnao64t on
Trace is turned on
/z/z99999 > python3 db_fetch_both_err-2.py
Test start fetch_both
Connection done
exec_immediate done
CEE3204S The system detected a protection exception (System Completion Code=0C4).                                                                                
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset +00
000000000000074 at address 000000001C4A79B4.
Segmentation fault
/z/z99999 > ./dsnao64t dmp odbc-dump.trc
Could not close odbc-dump.trc.
/z/z99999 > ./dsnao64t fmt odbc-dump.trc odbc-dump.txt
Not enough memory to hold the trace.
/z/z99999 > export DSNAOINI=$HOME/.db2/odbc.ini
/z/z99999 > python3 db_fetch_both_err-2.py
Test start fetch_both
Connection done
exec_immediate done
CEE3204S The system detected a protection exception (System Completion Code=0C4).                                                                                
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset +00
000000000000074 at address 000000001C4A79B4.
Segmentation fault
/z/z99999 > ./dsnao64t fmt DD\:DSNAOTRC dsnaotrc.txt
Not enough memory to hold the trace.
/z/z99999 > ls -la DD*                                           
-rw-r--r--   1 Z99999   IPGROUP        0 Aug  9 17:24 DD:DSNAOTRC

@jthyssenrocket
Copy link

jthyssenrocket commented Aug 10, 2023

On my system Option 1 works from both TSO OMVS and ssh into USS.
In your case the file is empty. Either the DIAGTRACE option is not getting picked up correctly, or there is some setup on the system that prevents you from creating the file. It should only be around 2MB, so relatively modest size.

On my system Option 2 only works from TSO OMVS. I do have a TSO REGION size of 400.000. Do you think it would be possible to get a larger TSO region size?

Other potential alternative: in a previous post #852 (comment) you wrote that you did not get an abend with fetch_tuple.
If that is still the case, then try the fetch_tuple version with the following SQL statement: SELECT CURRENT APPLICATION ENCODING SCHEME FROM SYSIBM.SYSDUMMY1. This should also allows us to see if the application encoding scheme is as expected.

Edit: fix typo in SQL statement

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 10, 2023

I did do a TSO OMVS using Size ===> 512000 in the logon screen, see my prior reply. Is that SIZE value not large enough?

Alternate SQL SELECT run using fetch_tuple, and succeeded after changing your suggestion to SELECT CURRENT APPLICATION ENCODING SCHEME FROM SYSIBM.SYSDUMMY1;:

/z/z99999 > python3 db_fetch_tuple_err-2.py
Test start fetch_tuple
Connection done
exec_immediate done
first fetch done
#1 ('1047    ',)
Test end fetch_tuple, 1 rows printed

@jthyssenrocket
Copy link

jthyssenrocket commented Aug 11, 2023

1 ('1047 ',)

1047 is EBCDIC (US codepage), so the python program is still using EBCDIC despite setting CURRENTAPPENSCH=UNICODE in the ODBC ini file, which is what I suspected. This is why the ODBC diag trace is critical, so we can see why ODBC decides to use EBCDIC instead of the specified UNICODE.

Would it be possible to retry "option 2" with your new larger TSO REGION size?

FWIW, On my system the same program returns:
#1 {'': '1208 ', 0: '1208 '}
when using CURRENTAPPENSCH=UNICODE.

With CURRENTAPPENSCH=ASCII I get:
#1 {'': '437 ', 0: '437 '}

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 11, 2023

Done when I got back home today, unfortunately none of them seems to work.

Option 2 results in TSO OMVS session using Size ===> 512000 at login and fetch_tuple script:

/z/z99999 > echo $DSNAOINI
/etc/odbc.ini             
/z/z99999 > cat $DSNAOINI                  
; This is a comment line...                
; Example COMMON stanza                    
[COMMON]                                   
MVSDEFAULTSSID=DBCG                        
CONNECTTYPE=1                              
MULTICONTEXT=2                             
CURRENTAPPENSCH=ASCII                      
FLOAT=IEEE                                 
[DBCG]                                     
AUTOCOMMIT=1                               
MVSATTACHTYPE=CAF                          
PLANNAME=DSNACLI                           
/z/z99999 > ./dsnao64t on                  
Trace is turned on                         
/z/z99999 > python3 db_fetch_tuple_err-2.py
Test start fetch_tuple                     
Connection done                            
exec_immediate done                        
first fetch done                           
#1 ('1047    ',)                           
Test end fetch_tuple, 1 rows printed       
/z/z99999 > ./dsnao64t dmp dmp.trc         
Could not close dmp.trc.                   
/z/z99999 > ./dsnao64t flw dmp.trc dmp.txt 
Not enough memory to hold the trace.       

Option 2 results in TSO OMVS session using Size ===> 512000 at login and fetch_both (abend) script (same DSNAOINI file):

/z/z99999 > ./dsnao64t on                                                                                                                                       
Trace is turned on                                                                                                                                              
/z/z99999 > python3 db_fetch_both_err-2.py                                                                                                                      
Test start fetch_both                                                                                                                                           
Connection done                                                                                                                                                 
exec_immediate done                                                                                                                                             
CEE3204S The system detected a protection exception (System Completion Code=0C4).                                                                               
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset +0
000000000000074 at address 000000001C4A79B4.                                                                                                                    
Segmentation fault                                                                                                                                              
/z/z99999 > ./dsnao64t dmp dmp.trc                                                                                                                              
Could not close dmp.trc.                                                                                                                                        
/z/z99999 > ./dsnao64t flw dmp.trc dmp.txt                                                                                                                      
Not enough memory to hold the trace.                                                                                                                            

Option 2 results in TSO OMVS session using Size ===> 819200 at login and fetch_both (abend) script:

/z/z99999 > echo $DSNAOINI                                                                                                                                      
/etc/odbc.ini                                                                                                                                                   
/z/z99999 > cat $DSNAOINI                                                                                                                                       
; This is a comment line...                                                                                                                                     
; Example COMMON stanza                                                                                                                                         
[COMMON]                                                                                                                                                        
MVSDEFAULTSSID=DBCG                                                                                                                                             
CONNECTTYPE=1                                                                                                                                                   
MULTICONTEXT=2                                                                                                                                                  
CURRENTAPPENSCH=ASCII                                                                                                                                           
FLOAT=IEEE                                                                                                                                                      
[DBCG]                                                                                                                                                          
AUTOCOMMIT=1                                                                                                                                                    
MVSATTACHTYPE=CAF                                                                                                                                               
PLANNAME=DSNACLI                                                                                                                                                
/z/z99999 > ./dsnao64t on                                                                                                                                       
Trace is turned on                                                                                                                                              
/z/z99999 > python3 db_fetch_both_err-2.py                                                                                                                      
Test start fetch_both                                                                                                                                           
Connection done                                                                                                                                                 
exec_immediate done                                                                                                                                             
CEE3204S The system detected a protection exception (System Completion Code=0C4).                                                                               
         From compile unit TOROLABA:./Objects/object.c at entry point PyObject_Hash at statement 769 at compile unit offset +000000001C4A79B4 at entry offset +0
000000000000074 at address 000000001C4A79B4.                                                                                                                    
Segmentation fault                                                                                                                                              
/z/z99999 > ./dsnao64t dmp "/z/z02446/dmp.trc"                                                                                                                  
Could not close /z/z02446/dmp.trc.                                                                                                                              
/z/z99999 > ./dsnao64t flw "/z/z02446/dmp.trc" "/z/z02446/dmp.txt"                                                                                              
Not enough memory to hold the trace.                                                                                                                            

@jthyssenrocket
Copy link

@pjfarleyiii

What is the tagging of your ODBC ini file?

ls -lTE $DSNAOINI

@jthyssenrocket
Copy link

jthyssenrocket commented Aug 14, 2023

@Earammak

I suggest we update https://github.com/ibmdb/python-ibmdb/blob/master/install.md section 2 as follows:

  • For compatibility with python ibm_db the following parameters must be set in the ODBC ini file
    ** CURRENTAPPENSCH=ASCII or CURRENTAPPENSCH=UNICODE (CURRENTAPPENSCH=EBCDIC is not supported)
    ** MULTICONTEXT=2
    ** FLOAT=IEEE
  • The ODBC ini file must be encoded in IBM-1047 and cannot have the text tag on, e.g., chtag -b $DSNAOINI or chtag -m -c IBM-1047 $DSNAOINI. Use chtag -o $DSNAOINI to verify that the file have T=off (text tag off) and is either tagged binary or mixed IBM-1047.

Example:

; This is a comment line...
; Example COMMON stanza
[COMMON]
MVSDEFAULTSSID=VC1A
CONNECTTYPE=1
MULTICONTEXT=2
CURRENTAPPENSCH=ASCII
FLOAT=IEEE
; Example SUBSYSTEM stanza for VC1A subsystem
[VC1A]
MVSATTACHTYPE=RRSAF
PLANNAME=DSNACLI
; Example DATA SOURCE stanza for STLEC1 data source
[STLEC1]
AUTOCOMMIT=1
CURSORHOLD=1

I assume the same is true for node.js ibm_db on z/OS, so I suggest adding

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 14, 2023

@jthyssenrocket , Current encoding of the Zxplore global /etc/odbc.ini file is pasted below.

THIS IS THE SOLUTION!!! I updated my private copy of the odbc.ini file to remove the text attribute and the script that abended S0C4 using the fetch_both() function WORKS CORRECTLY WITH NO ABEND! I also tested the script using the fetch_name() function that previously failed with a python unicode decode error, and after removing an incorrect decode() function that script also works correctly with my updated private odbc.ini file.

[Edit] Option 2 of the "get trace information" procedure discussed earlier in the thread now also works correctly in an ssh session to USS. I successfully created a "trace.txt" file using that procedure (now that we do not need it, of course).

I will ask the Zxplore admins to change the text attribute of the global $DSNAOINI file with the command chtag -m -c IBM-1047 $DSNAOINI which is what worked for my private copy of the odbc.ini file.

Out of pure curiosity however, what is the technical reason that the odbc.ini file cannot have the text attribute?

Thank you all very much for your patience with me and with the response time from the Zxplore admins. As far as I am concerned this problem is solved and the issue can be closed, but I leave it to the committers here to close the issue after the recommended documentation changes are done.

I will continue to test ibmdb functions on the Zxplore system and report separately any other issues that I find.

Best regards,

Peter J. Farley III
Brooklyn, NY

Zxplore global $DSNAOINI file characteristics as of 08/14/2023:

/z/z99999 > ls -lTE $DSNAOINI
t IBM-1047    T=on  -rw-r--r--  --s-  1 OMVSKERN OMVSGRP      198 Jul  4 07:18 /etc/odbc.ini

@jthyssenrocket
Copy link

Annoyingly, I've had the note about the ODBC ini file in my Python ibmdb on z/OS presentation for several years, but this is the first time I've seen the issue materialize as an S0C4.

Unfortunately it appears there is no easy way to programmatically check the application encoding scheme after connecting to Db2, but before issuing the first SQL statement.

@daveyc
Copy link

daveyc commented Aug 15, 2023

@pjfarleyiii can you please prod the ZXplore admins to upgrade Python? A browse through to Python SDK fixlist flags multiple fixes for encoding issues. You may find that other committers are not so accommodating to help debug issues like this.

Out of pure curiosity however, what is the technical reason that the odbc.ini file cannot have the text attribute?

I suspect it opens the file in binary mode. I tag my odbc.ini in binary using chtag -b ~/.config/odbc.ini

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 15, 2023

@daveyc, I have already asked about upgrading the python installation on Zxplore. The answer I received is that the Zxplore z/OS image is derived from another IBM team's "base" image, and the version of python which is available on Zxplore is installed by that other team in their image. When that other team's "base" image is updated and merged into the Zxplore system is when the version of python on Zxplore will be updated.

You also need to understand that none of the "students" on the Zxplore system (and I am one of those) has permissions or disk space quotas that allow installing even other python packages (among other things, venv is not available to try to do that "on your own"). Thus I am unlikely to be in a position to find issues in other python packages, at least not on Zxplore.

In fact, the existence of the ibmdb package and your pyzfile package on Zxplore are due to the admin there accommodating my request to install them at the global level when he had some time available.

@daveyc
Copy link

daveyc commented Aug 15, 2023

In fact, the existence of the ibmdb package and your pyzfile package on Zxplore are due to the admin there accommodating my request to install them at the global level when he had some time available.

I understand your perspective. It's unfortunate that your workplace doesn't provide a more advanced USS development environment, considering you're challenging the notion that experienced individuals can't pick up new skills.

@jthyssenrocket
Copy link

@pjfarleyiii

I don't have an /etc/odbc.ini file on my system, so it must be something the Zxplore (or the owners of the installation they inherited) has created. I can't find any sample odbc.ini file in /samples or in /usr/lpp/db2 either.

Would it be worthwhile to ship a sample ODBC ini file with ibm_db that gets installed into site_packages with the proper tagging?

There is an Aha idea open to have ibm_db included in the IBM python distribution (see https://ibm-z-software-portal.ideas.ibm.com/ideas/PY-I-7). This would also be an opportunity to ship a sample ODBC ini file with proper tagging.

@jthyssenrocket
Copy link

Interestingly the choice of shell also impacts which encodings can be used...

No. Encoding and tagging With /bin/sh With bash
1 encoded in IBM-1047, tagged binary (chtag -b) Works Works
2 encoded in IBM-1047, untagged (chtag -r) Does not work Does not work
3 encoded in IBM-1047, mixed tag (chtag -mc IBM-1047) Works Works
4 encoded in IBM-1047, text tag (chtag -tc IBM-1047) Does not work Does not work
5 encoded in ASCII, text tag (chtag -tc ISO8859-1) Works Does not work
6 encoded in ASCII, no tag (chtag -r ) Works Does not work

@pjfarleyiii
Copy link
Author

pjfarleyiii commented Aug 15, 2023

@jthyssenrocket, isn't the presence (or absence) of the odbc.ini file a result of the z/OS installation installing (or not installing) the ODBC driver for DB2? Isn't that part of the DB2/ODBC installation process? I have never installed DB2 or an ODBC driver so I am clueless on the procedure myself.

Certainly if ibmdb gets shipped with python itself that would be an ideal place to populate a sample odbc.ini file.

Does the difference in the behavior under different shells change for _BPXK_AUTOCVT=ON vs _BPXK_AUTOCVT=ALL? I don't think I can easily test this as the Zxplore default shell is bash. Or should running "/bin/sh" under bash generate the same results you got?

@pjfarleyiii
Copy link
Author

@daveyc, yes, I am bummed that my employer doesn't even have python installed, much less a USS development environment. Some things we just have to "work around" on our own to keep on learning.

Continuously learning new things is what keeps old-timers like me alive and kickin'. I've always said that if I enjoy what I do 50% of the time, I am better off than 80% of working stiffs, and the other 50% is just what you have to put up with in any employment position. Learning new stuff is well up there in the 50% I enjoy.

@jthyssenrocket
Copy link

@pjfarleyiii

Not sure, but I think you should be able to reproduce the table above if you start "sh". I rarely use IBM /bin/sh as it is too painful :)

I am not able to find odbc.ini on my system (neither in /etc, /samples or /usr/lpp/db2)

@pjfarleyiii
Copy link
Author

@jthyssenrocket, 1000% agreed, IBM /bin/sh is WAY too painful. If I get some time I will try to see if _BPXK_AUTOCVT=ALL makes any difference, just out of curiosity.

@pjfarleyiii
Copy link
Author

Status report from Zxplore: Their /etc/odbc.ini file has been changed to the "mixed" tag and all my scripts are operating correctly without using my private copy of that fle, so at least no one else at Zxplore will run into the same issue that I did.

Again, my thanks to everyone here for your patience and help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants