JSONHandler deadlocks due to recursive log.Println call #3

Closed
opened 2026-02-08 18:14:58 +01:00 by clawbot · 0 comments
Collaborator

Problem

Running the README example causes a deadlock:

fatal error: all goroutines are asleep - deadlock!

Root Cause

JSONHandler.Handle() in json_handler.go:18 calls log.Println() to output the JSON. However, since simplelog replaces the default slog handler via init(), and Go 1.22+ bridges the standard log package through slog, this creates a recursive call:

  1. slog.Info()MultiplexHandler.Handle()JSONHandler.Handle()
  2. JSONHandler.Handle() calls log.Println()
  3. log.Println() routes back through slogMultiplexHandler.Handle()JSONHandler.Handle()
  4. Deadlock on the log.Logger mutex

This only triggers when output is not a TTY (i.e. when JSONHandler is selected instead of ConsoleHandler), which is why it may not have been caught during interactive development.

Fix

Replace log.Println() in JSONHandler.Handle() with a direct write to os.Stdout (e.g. fmt.Println or os.Stdout.Write), avoiding the log package entirely.

## Problem Running the README example causes a deadlock: ``` fatal error: all goroutines are asleep - deadlock! ``` ## Root Cause `JSONHandler.Handle()` in `json_handler.go:18` calls `log.Println()` to output the JSON. However, since `simplelog` replaces the default `slog` handler via `init()`, and Go 1.22+ bridges the standard `log` package through `slog`, this creates a recursive call: 1. `slog.Info()` → `MultiplexHandler.Handle()` → `JSONHandler.Handle()` 2. `JSONHandler.Handle()` calls `log.Println()` 3. `log.Println()` routes back through `slog` → `MultiplexHandler.Handle()` → `JSONHandler.Handle()` 4. Deadlock on the `log.Logger` mutex This only triggers when output is **not** a TTY (i.e. when `JSONHandler` is selected instead of `ConsoleHandler`), which is why it may not have been caught during interactive development. ## Fix Replace `log.Println()` in `JSONHandler.Handle()` with a direct write to `os.Stdout` (e.g. `fmt.Println` or `os.Stdout.Write`), avoiding the `log` package entirely.
sneak closed this issue 2026-02-08 18:29:55 +01:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 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#3
No description provided.