Random crashes when using Console Writer and multiple goroutines
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with formatter.go:115 and the ConsoleWriter.write call at console.go:62; inspect how the entry buffer is used while concurrent goroutines write logs. Reproduce on Windows with the Console Writer and multiple goroutines, including the emoji log line. Done means the crash is fixed and a regression test covers concurrent logging.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
They are very very random but they all pop at the same time, always the same error, same function involved, no code change between errors.
Using version 1.0.119
This is the crash: happenes just after printing a line that has emoticon.
log.Info().Str("address", config.Server.ListenAddress).Msg("🌐 Starting HTTP server")
Then.. CRASH
unexpected fault address 0xffffffffffffffff
fatal error: fault
[signal 0xc0000005 code=0x0 addr=0xffffffffffffffff pc=0x81e3e5]
goroutine 1 gp=0xc0000021c0 m=0 mp=0x1054320 [running]:
runtime.throw({0xc066a5?, 0xc00016fb00?})
C:/Program Files/Go/src/runtime/panic.go:1101 +0x4d fp=0xc00016fac8 sp=0xc00016fa98 pc=0x715e4d
runtime.sigpanic()
C:/Program Files/Go/src/runtime/signal_windows.go:414 +0xd0 fp=0xc00016fb10 sp=0xc00016fac8 pc=0x6f7c70
github.com/phuslu/log.parseFormatterArgs({0xc000302100, 0x70, 0x100}, 0xc00016fd30?)
E:/Sources/go/sdk/Tekert/go/pkg/mod/github.com/phuslu/[email protected]/formatter.go:115 +0x485 fp=0xc00016fbd8 sp=0xc00016fb10 pc=0x81e3e5
github.com/phuslu/log.(*ConsoleWriter).write(0xc0001ba5e0, {0xcce100, 0xc000070068}, {0xc000368000, 0x70, 0x400})
E:/Sources/go/sdk/Tekert/go/pkg/mod/github.com/phuslu/[email protected]/console.go:62 +0x19c fp=0xc00016fc80 sp=0xc00016fbd8 pc=0x81931c
github.com/phuslu/log.(*ConsoleWriter).WriteEntry(0xc0001c6348?, 0x27?)
E:/Sources/go/sdk/Tekert/go/pkg/mod/github.com/phuslu/[email protected]/console_windows.go:42 +0x7e fp=0xc00016fcc0 sp=0xc00016fc80 pc=0x81b1de
IA analisys:
Analysis
Consistent Crash Point: All three stack traces you've provided are identical in their cause. They all crash inside github.com/phuslu/log.parseFormatterArgs with a memory access violation (addr=0xffffffffffffffff). This function is called by log.(*ConsoleWriter).write.
The Root Cause is a Race Condition: This is a classic race condition related to resource pooling. The phuslu/log library uses a sync.Pool to reuse log.Entry objects for performance. Here's the sequence of events that leads to the crash:
Your application starts up, and multiple goroutines (main, http server, etw session) begin logging concurrently.
Goroutine A calls log.Info()...Msg("..."). It gets a log.Entry object from the pool and writes the log data into its internal buffer (e.buf).
The Msg() function calls the writer's WriteEntry method. In your case, this is main.(*safeWriter).WriteEntry.
Crucially, as soon as the WriteEntry call is made, the log.Entry object is put back into the sync.Pool for reuse (logger.go:1849).
Goroutine B, running concurrently, makes another log call. It gets the exact same log.Entry object that Goroutine A just returned to the pool.
Goroutine B immediately resets the buffer (e.buf = e.buf[:0]) to write its own log message.
Meanwhile, the ConsoleWriter from Goroutine A's call is still busy parsing the buffer in parseFormatterArgs. It suddenly finds that the memory it's reading has been wiped or overwritten, leading to the memory access violation and the crash.
- Lingua principale
- Go
- Stelle
- 881
- Fork
- 64
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di phuslu/log
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
-
Fails to build in gccgoAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
-
bug: ConsoleWriterAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 32/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
-
bug triage/pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
core enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
forgelab-dev/lfa-forgenet#109 ·
I maintainer di solito rispondono entro 1 giorno
-
[mesheryctl] Enforce maximum positional argument bounds in system context view to prevent silent argument discardingForse già presa @madhavzanwar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
meshery/meshery#24055 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno