Skip to content

fix(engine): avoid panic with concurrent map read and map write (#503)

Artyom Kartasov requested to merge clone-counter-map into master

Description

Avoid panic with concurrent map read and map write

fatal error: concurrent map read and map write
2023/04/19 22:12:06 snapshots.go:57: [DEBUG]  snapshot: {snapshot_20230419204824 2023-04-19 20:48:24 +0000 UTC 2023-04-19 20:48:24 +0000 UTC}
2023/04/19 22:12:06 util.go:37: [DEBUG]  Response: &{ch06edk1fbtc73eh1cu0 0xc000010190 false <nil> 2023-04-19 22:12:06.881386769 +0000 UTC m=+5032.083750020 {CREATING Clone is being created.} {   } {0 0 0 0}}
2023/04/19 22:12:06 routes.go:150: [DEBUG]  Clone is being created

goroutine 6107 [running]:
runtime.throw({0xfe30cd?, 0x1?})
	/usr/local/go/src/runtime/panic.go:992 +0x71 fp=0xc000297448 sp=0xc000297418 pc=0x433f71
runtime.mapaccess1_faststr(0xe7a7a0?, 0xc00070bec0?, {0xc0000343c0, 0x14})
	/usr/local/go/src/runtime/map_faststr.go:22 +0x3a5 fp=0xc0002974b0 sp=0xc000297448 pc=0x4128c5
gitlab.com/postgres-ai/database-lab/v3/internal/cloning.(*Base).fetchSnapshots(0xc0001b8000)
	/builds/postgres-ai/database-lab/engine/internal/cloning/snapshots.go:39 +0x4a5 fp=0xc000297638 sp=0xc0002974b0 pc=0xa31be5
gitlab.com/postgres-ai/database-lab/v3/internal/cloning.(*Base).CreateClone(0xc0001b8000, 0xc0002864e0)
	/builds/postgres-ai/database-lab/engine/internal/cloning/base.go:140 +0x149 fp=0xc000297728 sp=0xc000297638 pc=0xa2e069
gitlab.com/postgres-ai/database-lab/v3/internal/srv.(*Server).createClone(0xc0004f4a20, {0x119efb8, 0xc0000d7c00}, 0xc0005ef810?)
	/builds/postgres-ai/database-lab/engine/internal/srv/routes.go:126 +0xa9 fp=0xc000297818 sp=0xc000297728 pc=0xd77869
gitlab.com/postgres-ai/database-lab/v3/internal/srv.(*Server).createClone-fm({0x119efb8?, 0xc0000d7c00?}, 0xc0002864b0?)
	<autogenerated>:1 +0x3c fp=0xc000297848 sp=0xc000297818 pc=0xd7f01c
gitlab.com/postgres-ai/database-lab/v3/internal/srv/mw.(*Auth).Authorized.func1({0x119efb8, 0xc0000d7c00}, 0xc000537a00)
	/builds/postgres-ai/database-lab/engine/internal/srv/mw/auth.go:44 +0xae fp=0xc0002978b0 sp=0xc000297848 pc=0xd73aee
net/http.HandlerFunc.ServeHTTP(0xc000537900?, {0x119efb8?, 0xc0000d7c00?}, 0x17c11e0?)
	/usr/local/go/src/net/http/server.go:2084 +0x2f fp=0xc0002978d8 sp=0xc0002978b0 pc=0x74cfaf
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0003da480, {0x119efb8, 0xc0000d7c00}, 0xc0001d0a00)
	/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x1cf fp=0xc000297a00 sp=0xc0002978d8 pc=0xd56d6f
gitlab.com/postgres-ai/database-lab/v3/internal/srv/mw.Logging.func1({0x119efb8, 0xc0000d7c00}, 0xc0001d0a00)
	/builds/postgres-ai/database-lab/engine/internal/srv/mw/logging.go:17 +0xed fp=0xc000297a70 sp=0xc000297a00 pc=0xd7448d
net/http.HandlerFunc.ServeHTTP(0x0?, {0x119efb8?, 0xc0000d7c00?}, 0x40d2c5?)
	/usr/local/go/src/net/http/server.go:2084 +0x2f fp=0xc000297a98 sp=0xc000297a70 pc=0x74cfaf
net/http.serverHandler.ServeHTTP({0x119c3a0?}, {0x119efb8, 0xc0000d7c00}, 0xc0001d0a00)
	/usr/local/go/src/net/http/server.go:2916 +0x43b fp=0xc000297b58 sp=0xc000297a98 pc=0x750a5b
net/http.(*conn).serve(0xc0004d10e0, {0x119f928, 0xc0005fe150})
	/usr/local/go/src/net/http/server.go:1966 +0x5d7 fp=0xc000297fb8 sp=0xc000297b58 pc=0x74ba57
net/http.(*Server).Serve.func3()
	/usr/local/go/src/net/http/server.go:3071 +0x2e fp=0xc000297fe0 sp=0xc000297fb8 pc=0x7513ae
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc000297fe8 sp=0xc000297fe0 pc=0x463d41
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:3071 +0x4db

Related issue

#503 (closed)

Examples

Checklist

  • MR description has been reviewed
  • MR changes are functionally tested
  • MR does NOT have API/CLI changes OR there are API/CLI changes and they have been reviewed & DOCS ARE ADJUSTED (reference doc, etc)
  • MR does NOT have UI changes OR there are UI changes and they have been reviewed & UX IS REVIEWED
Edited by Artyom Kartasov

Merge request reports