Skip to content

fix: keep access logs when the request peer is gone - #35

Merged
vinismarques merged 3 commits into
mainfrom
fix/json-log-missing-client
Sep 22, 2026
Merged

vinismarques merged 3 commits into
mainfrom
fix/json-log-missing-client

Conversation

@vinismarques

Copy link
Copy Markdown
Member

Closes #34.

json_logging 1.5.1 dereferences Starlette's optional Request.client unguarded, so any request whose peer socket is already gone (kubelet resetting a timed-out readiness probe) loses its access-log line to a formatter traceback on stderr.

The issue suggested passing a custom extractor to init_request_instrument, but that function has no such parameter: the extractor class comes from json_logging's framework registry and is frozen into the RequestUtil singleton by init_fastapi. So request_logging.py subclasses FastAPIRequestInfoExtractor and re-registers it via register_framework_support, called immediately before init_fastapi. Once upstream ships bobbui/json-logging-python#116 the module can be deleted.

Dropping init_request_instrument (the issue's other option) was rejected: it removes every access log, a larger behaviour change than the bug, and an upstream release would not undo it.

Covered by unit tests on both accessors and the registry swap, plus a subprocess test that drives /health with scope["client"] = None and asserts no logging error on stderr; it fails without the fix. Subprocess because json_logging.init_* mutates process-wide logging state irreversibly.

@vinismarques
vinismarques merged commit 1a9a57c into main Sep 22, 2026
1 check passed
@vinismarques
vinismarques deleted the fix/json-log-missing-client branch September 22, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json access-log formatter crashes when request.client is None

1 participant