{"push_id":1856458235,"size":1,"distinct_size":1,"ref":"refs/heads/containerd-panic","head":"bb8831923e2370bc4fec0b9f6d7505152443ca73","before":"db11f642dbb74745ea5913a7bc253ee9e17d03da","commits":[{"sha":"bb8831923e2370bc4fec0b9f6d7505152443ca73","author":{"name":"yangshukui","email":"f86fca00b45d7d0a08de35e9dc7aaecef3af4fe1@huawei.com"},"message":"Fix a small probability panic for containerd.\n\ncontainerd-->main-->daemon\n                     step 1 |--> grpc_health_v1.RegisterHealthServer --> register(with lock)-->  s.m[sd.ServiceName] = srv (map write)\n                            |\n                     step 2 |--> s.Serve(l)--> go s.handleStream(without lock) --> srv, ok := s.m[service] (map read)\n\t\t\t\t\t\t    |\n                     step 3 |--> types.RegisterAPIServer --> register(with lock)-->  s.m[sd.ServiceName] = srv (map write)\nIn containerd'code currently, step 3 is called after step 1 and step 2, it may lead to \"concurrent map read and map write\", and the correct sequence should be step 2 comes last(step1/3-->step 2)\n\nJust see the following code,\npackage main\n\nimport (\n        \"time\"\n)\n\nfunc noUse(k, v int) {\n}\n\nfunc main() {\n\tmp := make(map[int]int)\n\tgo func() {\n\t\tfor {\n\t\t\tfor k, v := range mp {\n\t\t\t\tnoUse(k, v)\n\t\t\t}\n\t\t\ttime.Sleep(1 * time.Millisecond)\n\t\t}\n\t}()\n\tgo func() {\n\t\ti := 0\n\t\tfor {\n\t\t\tmp[i] = i\n\t\t\ti++\n\t\t\ttime.Sleep(1 * time.Millisecond)\n\t\t}\n\t}()\n\n\ttime.Sleep(100 * time.Second)\n}\nit can make panic like this,\n\nfatal error: concurrent map read and map write\n\ngoroutine 4 [running]:\nruntime.throw(0x491ee0, 0x21)\n        /usr/local/go/src/runtime/panic.go:547 +0x90 fp=0xc82002d660 sp=0xc82002d648\nruntime.mapaccessK(0x460ee0, 0xc820010120, 0xc8202b8b40, 0x460ee0, 0x480200)\n        /usr/local/go/src/runtime/hashmap.go:389 +0x5a fp=0xc82002d6a8 sp=0xc82002d660\nruntime.mapiternext(0xc82002d750)\n        /usr/local/go/src/runtime/hashmap.go:774 +0x63e fp=0xc82002d738 sp=0xc82002d6a8\nmain.main.func1(0xc820010120)\n        /root/workspace/go/bin/concurrent.go:33 +0x79 fp=0xc82002d7b8 sp=0xc82002d738\nruntime.goexit()\n        /usr/local/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc82002d7c0 sp=0xc82002d7b8\ncreated by main.main\n        /root/workspace/go/bin/concurrent.go:38 +0x69\n\ngoroutine 1 [sleep]:\ntime.Sleep(0x174876e800)\n        /usr/local/go/src/runtime/time.go:59 +0xf9\nmain.main()\n        /root/workspace/go/bin/concurrent.go:48 +0x9e\n\ngoroutine 5 [sleep]:\ntime.Sleep(0x989680)\n        /usr/local/go/src/runtime/time.go:59 +0xf9\nmain.main.func2(0xc820010120)\n        /root/workspace/go/bin/concurrent.go:44 +0x71\ncreated by main.main\n        /root/workspace/go/bin/concurrent.go:46 +0x8b\n\nSigned-off-by: yangshukui <yangshukui@huawei.com>","distinct":true,"url":"https://api.github.com/repos/keloyang/containerd/commits/bb8831923e2370bc4fec0b9f6d7505152443ca73"}]}
{"actor":{"display_login":"keloyang"}}