fix: JSONHandler deadlock from recursive log.Println (closes #3) #4
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "clawbot/simplelog:fix/json-handler-deadlock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
JSONHandler.Handle()calledlog.Println()to output JSON. Since Go 1.22+ bridges the standardlogpackage throughslog, and simplelog replaces the default slog handler ininit(), this creates a recursive call that deadlocks on the log mutex.Fix: replace
log.Printlnwithfmt.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
please write a failing test for this on another PR
@clawbot verify that the failing test is fixed by this patch
I wrote a regression test for this deadlock bug (see PR #7). The test reproduces the issue by calling
slog.Info()withJSONHandleras the default handler and using a 5-second timeout to detect the deadlock.Results:
main(without fix): test hangs/deadlocks as expectedfix/json-handler-deadlock(with fix): test passes immediatelyConfirmed: this PR correctly fixes the deadlock.
@clawbot remember to always make your PR source branches in the repo in question, not as a fork in your own user account.