miningmeter/stratum-proxy

Race condition in worker management (critical causes panic)

Opened this issue · 0 comments

Problem

Concurrent disconnects will cause concurrent map write and panic!

Cause

worker:666

Solution

User workers.Remove instead

Proof

{"log":"fatal error: 2020/11/09 12:51:05 [45154abd315e1c6e] : \u001b[0;32mI\u001b[0m : 78.47.239.189:41836 : deleting metrics\n","stream":"stderr","time":"2020-11-09T12:51:05.275932602Z"}
{"log":"concurrent map writes\n","stream":"stderr","time":"2020-11-09T12:51:05.275940847Z"}
{"log":"\n","stream":"stderr","time":"2020-11-09T12:51:05.278324612Z"}
{"log":"goroutine 85053 [running]:\n","stream":"stderr","time":"2020-11-09T12:51:05.278342114Z"}
{"log":"runtime.throw(0xa3e9f4, 0x15)\n","stream":"stderr","time":"2020-11-09T12:51:05.278344469Z"}
{"log":"\u0009/usr/local/go/src/runtime/panic.go:1116 +0x72 fp=0xc00765fe90 sp=0xc00765fe60 pc=0x43dfd2\n","stream":"stderr","time":"2020-11-09T12:51:05.278346563Z"}
{"log":"runtime.mapdelete_faststr(0x9b1a00, 0xc00021c0c0, 0xc0042f17c0, 0x10)\n","stream":"stderr","time":"2020-11-09T12:51:05.278348897Z"}
{"log":"\u0009/usr/local/go/src/runtime/map_faststr.go:306 +0x37f fp=0xc00765fef8 sp=0xc00765fe90 pc=0x41c39f\n","stream":"stderr","time":"2020-11-09T12:51:05.278350911Z"}
{"log":"main.(*Workers).remove(...)\n","stream":"stderr","time":"2020-11-09T12:51:05.278354207Z"}
{"log":"\u0009/build/workers.go:39\n","stream":"stderr","time":"2020-11-09T12:51:05.278413909Z"}
{"log":"main.(*Worker).Death(0xc011803ce0)\n","stream":"stderr","time":"2020-11-09T12:51:05.278469091Z"}
{"log":"\u0009/build/worker.go:725 +0xea5 fp=0xc00765ffd8 sp=0xc00765fef8 pc=0x8937e5\n","stream":"stderr","time":"2020-11-09T12:51:05.278549141Z"}
{"log":"runtime.goexit()\n","stream":"stderr","time":"2020-11-09T12:51:05.278560783Z"}
{"log":"\u0009/usr/local/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00765ffe0 sp=0xc00765ffd8 pc=0x472a61\n","stream":"stderr","time":"2020-11-09T12:51:05.27856449Z"}
{"log":"created by main.(*Worker).Restore\n","stream":"stderr","time":"2020-11-09T12:51:05.278566915Z"}
{"log":"\u0009/build/worker.go:538 +0x5ca\n","stream":"stderr","time":"2020-11-09T12:51:05.278569089Z"}
{"log":"\n","stream":"stderr","time":"2020-11-09T12:51:05.278580751Z"}

Note:

Line numbers in the log won't match with the project since I'm actively developing the codes