JSONHandler deadlocks due to recursive log.Println call #3
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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?
Problem
Running the README example causes a deadlock:
Root Cause
JSONHandler.Handle()injson_handler.go:18callslog.Println()to output the JSON. However, sincesimplelogreplaces the defaultsloghandler viainit(), and Go 1.22+ bridges the standardlogpackage throughslog, this creates a recursive call:slog.Info()→MultiplexHandler.Handle()→JSONHandler.Handle()JSONHandler.Handle()callslog.Println()log.Println()routes back throughslog→MultiplexHandler.Handle()→JSONHandler.Handle()log.LoggermutexThis only triggers when output is not a TTY (i.e. when
JSONHandleris selected instead ofConsoleHandler), which is why it may not have been caught during interactive development.Fix
Replace
log.Println()inJSONHandler.Handle()with a direct write toos.Stdout(e.g.fmt.Printlnoros.Stdout.Write), avoiding thelogpackage entirely.