Skip to content

HTTP request handler: check sys.stderr != None before logging #89057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xiaolingbao mannequin opened this issue Aug 11, 2021 · 2 comments
Open

HTTP request handler: check sys.stderr != None before logging #89057

xiaolingbao mannequin opened this issue Aug 11, 2021 · 2 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xiaolingbao
Copy link
Mannequin

xiaolingbao mannequin commented Aug 11, 2021

BPO 44894

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2021-08-11.23:56:49.134>
labels = ['type-bug', 'library', '3.9']
title = 'HTTP request handler: check sys.stderr != None before logging'
updated_at = <Date 2021-08-13.23:02:22.093>
user = 'https://bugs.python.org/xiaolingbao'

bugs.python.org fields:

activity = <Date 2021-08-13.23:02:22.093>
actor = 'terry.reedy'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-08-11.23:56:49.134>
creator = 'xiaolingbao'
dependencies = []
files = []
hgrepos = []
issue_num = 44894
keywords = []
message_count = 2.0
messages = ['399423', '399470']
nosy_count = 1.0
nosy_names = ['xiaolingbao']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue44894'
versions = ['Python 3.9']

@xiaolingbao
Copy link
Mannequin Author

xiaolingbao mannequin commented Aug 11, 2021

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.

@xiaolingbao xiaolingbao mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir labels Aug 11, 2021
@xiaolingbao
Copy link
Mannequin Author

xiaolingbao mannequin commented Aug 12, 2021

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).

@xiaolingbao xiaolingbao mannequin added type-bug An unexpected behavior, bug, or error labels Aug 12, 2021
@terryjreedy terryjreedy changed the title HTTP request handler should check sys.stderr for None before use for logging HTTP request handler: check sys.stderr != None before logging Aug 13, 2021
@terryjreedy terryjreedy changed the title HTTP request handler should check sys.stderr for None before use for logging HTTP request handler: check sys.stderr != None before logging Aug 13, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants