cherti / mailexporter

Export Prometheus-style metrics about mail server functionality
https://prometheus.io
GNU General Public License v3.0
45 stars 9 forks source link

fatal error: concurrent map writes #36

Open Ekleog opened 2 years ago

Ekleog commented 2 years ago

Today, after around 5-10 hours of runtime, with 8 probes all configured to watch the same maildir (so /cur and /new as per #35) and one mail per minute with 1min timeout, the mail exporter crashed with the following message:

fatal error: concurrent map writes
goroutine 34628 [running]:
runtime.throw(0x..., 0x15)
        runtime/panic.go:1117 +0x72 fp=0x... sp=0x... pc=0x...
runtime.mapassign_faststr(0x..., 0x..., 0x..., 0x..., 0x0)
        runtime/map_faststr.go:211 +0x... fp=0x... sp=0x... pc=0x...
main.probe(0x..., 0x4, 0x..., 0x9, 0x..., 0x2, 0x0, 0x0, 0x0, 0x0, ...)
        github.com/cherti/mailexporter/mailexporter.go:366 +0x8e fp=0x... sp=0x... pc=0x...
runtime.goexit()
        runtime/asm_amd64.s:1371 +0x1 fp=0x... sp=0x... pc=0x...
created by main.monitor
        github.com/cherti/mailexporter/mailexporter.go:400 +0x1b4
goroutine 1 [IO wait, 479 minutes]:
[...]

If I understand correctly, the relevant code is https://github.com/cherti/mailexporter/blob/main/mailexporter.go#L366 ; in which case my guess would be it'd be enough to add a mutex around muxer.

Does that make sense to you? If so, I've never written any go yet but it feels like something I could write up a PR for :)

cherti commented 2 years ago

that does indeed sound like a plausible explanation for that behavior, and a mutex seems to be the right solution here. If you want to prepare a PR, you are very invited to do so. :)