oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
307 stars 59 forks source link

Async changes break connecting under certain circumstances #288

Closed jeamland closed 3 months ago

jeamland commented 5 months ago
  1. What versions are you using?

OCI ADB-S, ORDS version 23.2.3.242.1937

platform.platform: Linux-5.4.17-2136.326.6.el7uek.aarch64-aarch64-with-glibc2.28 sys.maxsize > 2**32: True platform.python_version: 3.9.18 oracledb.version: 2.0.1

  1. Is it an error or a hang or a crash?

Crash.

  1. What error(s) or behavior you are seeing?

I'm truncating the trace somewhat, but this illustrates the issue:

2024-01-29T23:52:31.39334   File "/seed_bank/lib64/python3.9/site-packages/sqlalchemy/engine/default.py", line 616, in connect
2024-01-29T23:52:31.39335     return self.loaded_dbapi.connect(*cargs, **cparams)
2024-01-29T23:52:31.39335   File "/seed_bank/lib64/python3.9/site-packages/oracledb/connection.py", line 1134, in connect
2024-01-29T23:52:31.39335     return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
2024-01-29T23:52:31.39335   File "/seed_bank/lib64/python3.9/site-packages/oracledb/connection.py", line 523, in __init__
2024-01-29T23:52:31.39335     impl.connect(params_impl)
2024-01-29T23:52:31.39336   File "src/oracledb/impl/thin/connection.pyx", line 449, in oracledb.thin_impl.ThinConnImpl.connect
2024-01-29T23:52:31.39336   File "src/oracledb/impl/thin/connection.pyx", line 445, in oracledb.thin_impl.ThinConnImpl.connect
2024-01-29T23:52:31.39336   File "src/oracledb/impl/thin/connection.pyx", line 411, in oracledb.thin_impl.ThinConnImpl._connect_with_params
2024-01-29T23:52:31.39337   File "src/oracledb/impl/thin/connection.pyx", line 392, in oracledb.thin_impl.ThinConnImpl._connect_with_description
2024-01-29T23:52:31.39337   File "src/oracledb/impl/thin/connection.pyx", line 365, in oracledb.thin_impl.ThinConnImpl._connect_with_address
2024-01-29T23:52:31.39337   File "src/oracledb/impl/thin/protocol.pyx", line 290, in oracledb.thin_impl.Protocol._connect_phase_two
2024-01-29T23:52:31.39337   File "src/oracledb/impl/thin/protocol.pyx", line 386, in oracledb.thin_impl.Protocol._process_message
2024-01-29T23:52:31.39338   File "src/oracledb/impl/thin/protocol.pyx", line 363, in oracledb.thin_impl.Protocol._process_message
2024-01-29T23:52:31.39338   File "src/oracledb/impl/thin/messages.pyx", line 311, in oracledb.thin_impl.Message.send
2024-01-29T23:52:31.39338   File "src/oracledb/impl/thin/messages.pyx", line 1766, in oracledb.thin_impl.AuthMessage._write_message
2024-01-29T23:52:31.39338 AttributeError: 'oracledb.thin_impl.WriteBuffer' object has no attribute '_socket'
  1. Does your application call init_oracle_client()?

No, we're using Thin mode.

  1. Include a runnable Python script that shows the problem.

That's a bit tricky but I can point out where the problem lies.

In my use case I'm attempting to connect to an ADB-S using IAM tokens. I've implemented a SQLAlchemy dialect that wraps their oracledb dialect and does the IAM parts. I believe that this is leading to enabling some use of authenticated/signed messages In oracledb.thin_impl.AuthMessage._write_message, when self.private_key is set, we attempt to call .getpeername() on the _socket attribute of the WriteBuffer. Unfortunately when the async changes came in that attribute was replaced by a _transport attribute but this code wasn't changed to fit.

anthony-tuininga commented 5 months ago

Thanks for the report. I'll get that fixed for the next release.

anthony-tuininga commented 4 months ago

I was able to replicate the issue and resolve it. If you are able to build from source you can verify that it works for you, too.

anthony-tuininga commented 3 months ago

This patch was included in version 2.1.0 which was just released.