This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: HTTP request handler: check sys.stderr != None before logging
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: xiaolingbao
Priority: normal Keywords:

Created on 2021-08-11 23:56 by xiaolingbao, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg399423 - (view) Author: Xiaoling Bao (xiaolingbao) Date: 2021-08-11 23:56
This is about HTTP server library (found on Windows with python 3.9, not sure other platforms).

In file Lib\http\server.py, we define:
class BaseHTTPRequestHandler(...):
  def log_message(self, format, *args):
    sys.stderr.write(...)

In certain cases, sys.stderr could be None and thus this function call will throw exception. My use case: I created an XMLRPC server (SimpleXMLRPCRequestHandler derives from BaseHTTPRequestHandler) within a Windows service. I guess with that combination, sys.stderr will be None. When this issue happens, the client got empty response and not much error log for debugging.

I can upload sample source code files if needed.
msg399470 - (view) Author: Xiaoling Bao (xiaolingbao) Date: 2021-08-12 16:30
It looks https://bugs.python.org/issue43348 has the same root cause as this one. When running with pythonservice.exe or pythonw.exe, sys.stderr will be None and thus causing crash when logging messages (calling sys.stderr.write).
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 89057
2021-08-13 23:02:22terry.reedysettitle: HTTP request handler should check sys.stderr for None before use for logging -> HTTP request handler: check sys.stderr != None before logging
2021-08-12 16:30:04xiaolingbaosettype: behavior
messages: + msg399470
2021-08-11 23:56:49xiaolingbaocreate