Skip to content

oauth_cb resulting in Core Dump - Fatal Python error: PyGILState_Release: auto-releasing thread-state, but no thread-state for this thread #2191

@mkmoisen

Description

If oauth_cb returns None, or None, None, the python application core dumps.

I'm trying to handle the case where the oauth_cb fails to get a bearer token for whatever reason. It would be nice to have an exception raised with my custom error message instead of "OAuth token not set within 10 seconds timeout".

from confluent_kafka import Consumer


conf = {
    'bootstrap.servers': 'foo.com:9096',
    'group.id': 'myconsumergroup',
    "security.protocol": 'SASL_SSL',
    'sasl.mechanism': 'OAUTHBEARER',
}


# Exception is swallowed and this function returns None, core dumping.
def oauth_cb(config):
    try:
        access_token, expiration_date = _get_access_token_and_expiration_date()
        return access_token, expiration_date
    except Exception as ex:
        print("\n\n\noauth_cb failed to get access_token", ex)

conf['oauth_cb'] = oauth_cb

consumer = Consumer(conf)

results in:

oauth_cb failed to get access_token name '_get_access_token_and_expiration_date' is not defined
Fatal Python error: PyGILState_Release: auto-releasing thread-state, but no thread-state for this thread
Python runtime state: initialized

Thread 0x00007f2f4b663b80 [python] (most recent call first):
  File "<python-input-0>", line 22 in <module>
  File "/opt/app-root/Python-3.14.0/Lib/_pyrepl/console.py", line 181 in runcode
  File "/opt/app-root/Python-3.14.0/Lib/_pyrepl/console.py", line 226 in runsource
  File "/opt/app-root/Python-3.14.0/Lib/code.py", line 324 in push
  File "/opt/app-root/Python-3.14.0/Lib/_pyrepl/simple_interact.py", line 151 in run_multiline_interactive_console
  File "/opt/app-root/Python-3.14.0/Lib/_pyrepl/main.py", line 58 in interactive_console

Aborted (core dumped)

In addition these variations result in the same:

def oauth_cb(config):
    return None, None

def oauth_cb(config):
    return None

However these two "work" in that it doesn't core dump, however there is no way to pass the reason for which the call failed:

def oauth_cb(config):
    try:
        access_token, expiration_date = _get_access_token_and_expiration_date()
        return access_token, expiration_date
    except Exception as ex:
        return 'a', -1

def oauth_cb(config):
    try:
        access_token, expiration_date = _get_access_token_and_expiration_date()
        return access_token, expiration_date
    except Exception as ex:
        raise Exception("auth_cb failed to get access_token due to invalid credentials")

Both result in:

Traceback (most recent call last):
File "", line 22, in
consumer = Consumer(conf)
cimpl.KafkaException: KafkaError{code=SASL_AUTHENTICATION_FAILED,val=58,str="OAuth token not set within 10 seconds timeout"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions