GrahamDumpleton / mod_wsgi

Source code for Apache/mod_wsgi.
Apache License 2.0
1.02k stars 268 forks source link

RuntimeError: log object has expired in mod_wsgi 5.0.1 with Django 5.0.9 python 3.13.0 #912

Open bdr-sara opened 5 days ago

bdr-sara commented 5 days ago

Summary

I'm encountering a RuntimeError: log object has expired when using mod_wsgi with Django 5.0.9. The issue appears in the Apache logs when rendering certain pages.

Environment

Steps to Reproduce

  1. Set up a Django 5.0.9 application with mod_wsgi and Apache.
  2. Visit a specific page or make an API request.
  3. Check the Apache error log.

Error Log

[Tue Oct 15 11:55:47.997506 2024] [wsgi ] [pid 8404 1060] [client xx:43833] File "C:\Apache24\htdocs\ERPapp.venv\Lib\site-packages\django\template\engine.py", line 20, in init [Tue Oct 15 11:55:47.997506 2024] [wsgi ] [pid 8404 1060] [client xx:43833] RuntimeError: log object has expired

GrahamDumpleton commented 5 days ago

This error indicates that something has cached the wsgi.errors object from the WSGI request environ dictionary beyond the lifetime of the HTTP request and has then tried to write to it after the request has finished.

It is very strange that something is actually trying to use the wsgi.errors object and not just using Python logging module and/or stderr instead. Don't thinkI have ever seen any framework use wsgi.errors even though it exists.

Would need the complete stack trace for the error to try and better understand what is trying to use it.

bdr-sara commented 5 days ago

it is apear on every API request and it is the partialstack trace: [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] File "C:\Apache24\htdocs\ERPapp\.venv\Lib\site-packages\django\template\base.py", line 339, in init\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] def init(self, template_string):\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] RuntimeError: log object has expired\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] Exception ignored in: <_io.TextIOWrapper name='' encoding='utf-8'>\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] Traceback (most recent call last):\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] File "C:\Apache24\htdocs\ERPapp\.venv\Lib\site-packages\django\template\base.py", line 339, in init\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] def init(self, template_string):\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] RuntimeError: log object has expired\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] Exception ignored in: <_io.TextIOWrapper name='' encoding='utf-8'>\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] Traceback (most recent call last):\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364043 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] File "C:\Apache24\htdocs\ERPapp\.venv\Lib\site-packages\django\template\base.py", line 339, in init\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364940 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] def init(self, template_string):\r, referer: https://wishproglobal.com:portX/ [Tue Oct 15 12:25:51.364940 2024] [wsgi:error] [pid 6868:tid 1220] [client xxx:36116] RuntimeError: log object has expired\r, referer: https://wishproglobal.com:portX/

GrahamDumpleton commented 5 days ago

Do the pages which have this issue use an on transaction commit callback, or other callback which is processed upon completion of a request, to do something? This is probably what is happening, and it is trying to access the now invalid wsgi.errors object somehow, possibly by trying to print on the WSGI environ dictionary inadvertently.

bdr-sara commented 5 days ago

Thanks for taking the time This happens to me on every API request I feel like I had a version compatibility issue when installing the django pyodbc,mod_wsgi library I addressed this bug https://github.com/mkleehammer/pyodbc/issues/1382 And i did as pip install git+https://github.com/mkleehammer/pyodbc.git

That could be causing me a problem Maybe it's better for me to go down to old versions in everything

GrahamDumpleton commented 5 days ago

Oh, didn't pick up that you were using Python 3.13. I wonder what has changed in that version. 🤔