eht16 / python-logstash-async

Python logging handler for sending log events asynchronously to Logstash.
MIT License
186 stars 51 forks source link

Can cause python code to hang in k8s deployment with python 3.11 #87

Closed kazmer97 closed 10 months ago

kazmer97 commented 1 year ago

Description

Long running python jobs deployed in k8s end up hanging during

my log stash setup:

logstash_enabled = config.LOGSTASH_ENABLED
    logstash_host = config.LOGSTASH_HOST
    logstash_port = config.LOGSTASH_PORT
    logstash_level = config.LOGSTASH_LEVEL

    if logstash_enabled:
        handler = AsynchronousLogstashHandler(
            logstash_host,
            logstash_port,
            database_path=None,
            event_ttl=600,
        )
        handler.setFormatter(FlaskLogstashFormatter(message_type="custteam"))
        handler.setLevel(logstash_level)
        logger = logging.getLogger(logger_name)
        logger.addHandler(handler)

gdb log trace:


File "/usr/local/lib/python3.11/threading.py", line 1132, in _wait_for_tstate_lock
if lock.acquire (block, timeout):
File "/usr/local/lib/python3.11/threading.py", line 1112, in join
self._wait_for_tstate_lock()
File "/usr/local/lib/python3.11/site-packages/logstash_async/handler.py", line 216, in _wait_for_worker_thread AsynchronousLogstashHandler._worker_thread.join()
File "/usr/local/lib/python3.11/site-packages/logstash_async/handler.py", line 204, in shutdown self._wait_for_worker_thread()
File "/usr/local/lib/python3.11/site-packages/logstash_async/handler.py", line 110, in close self.shutdown ()
File "/usr/local/lib/python3.11/logging/__init_ _•py", line 2193, in shutdown
h.close ()```
eht16 commented 1 year ago

Do you know if this happens only since 2.7.0 or also before?

It might be related to https://github.com/eht16/python-logstash-async/issues/83.

The workaround will be released later today.

kazmer97 commented 1 year ago

Only 2.7, downgrading to 2.6 solved this issue. Could be that I'm initialising something wrong.

eht16 commented 1 year ago

I think this is the same as in #83. I just pushed release 2.7.1, could you try it?

kazmer97 commented 1 year ago

I'll try it this week. Thanks for the quick response.