fix: JSONHandler deadlock from recursive log.Println (closes #3) #4
Odkázat v novém úkolu
Zablokovat Uživatele
Smazat větev „:fix/json-handler-deadlock“
Smazání větve je trvalé. Přestože zrušená větev může existovat i po krátkou dobu, než bude skutečně odstraněna, NELZE ji většinou vrátit. Pokračovat?
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.