fix: JSONHandler deadlock from recursive log.Println (closes #3) #4

Merged
sneak merged 2 commits from clawbot/simplelog:fix/json-handler-deadlock into main 2026-02-08 18:29:55 +01:00
Collaborator

JSONHandler.Handle() called log.Println() to output JSON. Since Go 1.22+ bridges the standard log package through slog, and simplelog replaces the default slog handler in init(), this creates a recursive call that deadlocks on the log mutex.

Fix: replace log.Println with fmt.Fprintln(os.Stdout, ...) to write directly without going through the log/slog bridge.

Tested with the README example — runs cleanly now instead of deadlocking.

Closes #3

`JSONHandler.Handle()` called `log.Println()` to output JSON. Since Go 1.22+ bridges the standard `log` package through `slog`, and simplelog replaces the default slog handler in `init()`, this creates a recursive call that deadlocks on the log mutex. Fix: replace `log.Println` with `fmt.Fprintln(os.Stdout, ...)` to write directly without going through the log/slog bridge. Tested with the README example — runs cleanly now instead of deadlocking. Closes #3
clawbot added 1 commit 2026-02-08 18:15:36 +01:00
Owner

please write a failing test for this on another PR

please write a failing test for this on another PR
Owner

@clawbot verify that the failing test is fixed by this patch

@clawbot verify that the failing test is fixed by this patch
Author
Collaborator

I wrote a regression test for this deadlock bug (see PR #7). The test reproduces the issue by calling slog.Info() with JSONHandler as the default handler and using a 5-second timeout to detect the deadlock.

Results:

  • On main (without fix): test hangs/deadlocks as expected
  • On fix/json-handler-deadlock (with fix): test passes immediately
=== RUN   TestJSONHandlerDeadlock
--- PASS: TestJSONHandlerDeadlock (0.00s)
PASS

Confirmed: this PR correctly fixes the deadlock.

I wrote a regression test for this deadlock bug (see PR #7). The test reproduces the issue by calling `slog.Info()` with `JSONHandler` as the default handler and using a 5-second timeout to detect the deadlock. **Results:** - ❌ On `main` (without fix): test hangs/deadlocks as expected - ✅ On `fix/json-handler-deadlock` (with fix): test passes immediately ``` === RUN TestJSONHandlerDeadlock --- PASS: TestJSONHandlerDeadlock (0.00s) PASS ``` Confirmed: this PR correctly fixes the deadlock.
Owner

@clawbot remember to always make your PR source branches in the repo in question, not as a fork in your own user account.

@clawbot remember to always make your PR source branches in the repo in question, not as a fork in your own user account.
sneak added 1 commit 2026-02-08 18:29:14 +01:00
sneak merged commit 9121da9aae into main 2026-02-08 18:29:55 +01:00
sneak deleted branch fix/json-handler-deadlock 2026-02-08 18:29:55 +01:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sneak/simplelog#4
No description provided.