panic: assignment to entry in nil map

Syncthing was down on a computer that I help administer remotely, and upon checking it I’ve found these panic logs. Unfortunately, I don’t what could’ve happened exactly. The system itself was still working when I logged into it, and it hadn’t run out of disk space or memory or anything like that beforehand.

This is Windows 10 x64 and the Syncthing version was v1.20.2 (custom built).

Have you got any idea what this problem may be about?

Panic at 2022-07-31T10:24:39+09:00
panic: assignment to entry in nil map

goroutine 30 [running]:
github.com/syncthing/syncthing/lib/model.(*deadlockDetector).watchInner(0xc00019cc00, {0x1a63b64, 0x4}, 0xc000fe3440)
	github.com/syncthing/syncthing/lib/model/util.go:73 +0x22c
github.com/syncthing/syncthing/lib/model.(*deadlockDetector).Watch.func1()
	github.com/syncthing/syncthing/lib/model/util.go:57 +0x65
created by github.com/syncthing/syncthing/lib/model.(*deadlockDetector).Watch
	github.com/syncthing/syncthing/lib/model/util.go:45 +0x115

goroutine 1 [chan receive, 118 minutes]:
github.com/syncthing/syncthing/lib/syncthing.(*App).Wait(...)
	github.com/syncthing/syncthing/lib/syncthing/syncthing.go:373
main.syncthingMain({{{0x1}, {0x0, 0x0}, {0xc00019f0c0, 0x39}, 0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
	github.com/syncthing/syncthing/cmd/syncthing/main.go:680 +0xd5e
main.serveOptions.Run({{{0x1}, {0x0, 0x0}, {0xc00019f0c0, 0x39}, 0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
	github.com/syncthing/syncthing/cmd/syncthing/main.go:402 +0x758
reflect.Value.call({0x1a55880?, 0x23ba3a0?, 0x1898465?}, {0x1a63794, 0x4}, {0xc000147b90, 0x0, 0x1012308?})
	reflect/value.go:556 +0x845
reflect.Value.Call({0x1a55880?, 0x23ba3a0?, 0x195c4c0?}, {0xc000147b90, 0x0, 0x0})
	reflect/value.go:339 +0xbf
github.com/alecthomas/kong.callMethod({0x1a631b2, 0x3}, {0x1a55880?, 0x23ba3a0?, 0x3?}, {0x1a55880?, 0x23ba3a0?, 0x0?}, 0x0?)
	github.com/alecthomas/kong@v0.3.0/callbacks.go:97 +0x4e7
github.com/alecthomas/kong.(*Context).RunNode(0xc0000ab000, 0xc00009a2d0, {0x0, 0x0, 0x0})
	github.com/alecthomas/kong@v0.3.0/context.go:735 +0x5f7
github.com/alecthomas/kong.(*Context).Run(0x18f10a0?, {0x0?, 0x0?, 0x0?})
	github.com/alecthomas/kong@v0.3.0/context.go:760 +0x14e
main.main()
	github.com/syncthing/syncthing/cmd/syncthing/main.go:255 +0x3b6

That’s a bug. The deadlock detector has detected that it took a long time to acquire a lock and is going to report it, but crashes because a thing isn’t properly initialized. I’ll fix it.

Thank you for looking into it, and for a very quick fix too (as usual)! :slightly_smiling_face: