go Map:maps.Clone中的段错误,

aelbi1ox  于 3个月前  发布在  Go
关注(0)|答案(8)|浏览(54)

Go版本

go版本:go1.22.5 darwin/arm64

在你的模块/工作区中运行go env的输出:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/radu/Library/Caches/go-build'
GOENV='/Users/radu/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/radu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/radu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/radu/go/src/github.com/cockroachdb/pebble/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/x0/5yrxw_4s271g705vjscld23c0000gq/T/go-build2422055407=/tmp/go-build -gno-record-gcc-switches -fno-common'

你做了什么?

这是一个测试,用于添加、删除和克隆Map:

func TestMapClone(t *testing.T) {
	seed := time.Now().UnixNano()
	t.Logf("seed: %d", seed)
	rng := rand.New(rand.NewSource(seed))
	for i := 0; i < 100; i++ {
		keyRange := 1 + rng.Intn(100)
		clone := make(map[string]int)
		m := make(map[string]int)
		for j := 0; j < 10000; j++ {
			switch rng.Intn(10) {
			case 0, 1, 2, 3, 4:
				m[fmt.Sprint(rng.Intn(keyRange))] = j
			case 5, 6, 7, 8:
				delete(m, fmt.Sprint(rng.Intn(keyRange)))
			case 9:
				clone = maps.Clone(m)
			}
			if rng.Intn(100) == 0 {
				// Revert to the last clone.
				m = clone
			}
		}
	}
}

你看到了什么发生?

在压力下(-exec 'stress -p 10')运行它,并在几千次运行后得到以下结果:

=== RUN   TestMapClone
    mem_fs_test.go:210: seed: 1724860257984210000
unexpected fault address 0x3731373330313337
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0x3731373330313337 pc=0x1005a5108]

goroutine 19 gp=0x14000104fc0 m=0 mp=0x100b594c0 [running]:
runtime.throw({0x10081e604?, 0x1009018c0?})
        /Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/panic.go:1023 +0x40 fp=0x14000066cf0 sp=0x14000066cc0 pc=0x1005cd780
runtime.sigpanic()
        /Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/signal_unix.go:895 +0x22c fp=0x14000066d50 sp=0x14000066cf0 pc=0x1005e786c
runtime.moveToBmap(0x1008d7900, 0x14000516ff0, 0x14000066e28?, 0x1005a7d40?, 0x3731373330313337)
        /Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/map.go:1456 +0x38 fp=0x14000066de0 sp=0x14000066d60 pc=0x1005a5108
runtime.mapclone2(0x1008d7900, 0x14000516d80)
        /Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/map.go:1538 +0x428 fp=0x14000066e80 sp=0x14000066de0 pc=0x1005a57e8
maps.clone({0x1008d7900, 0x14000516d80})
        /Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/map.go:1448 +0x2c fp=0x14000066ea0 sp=0x14000066e80 pc=0x10060272c
maps.Clone[...](...)
        /Users/radu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/maps/maps.go:46
github.com/cockroachdb/pebble/vfs.TestMapClone(0x14000135040)

你期望看到什么?

没有崩溃。

mm5n2pyu

mm5n2pyu1#

注意:这与#62203类似,但它是一个不同的代码路径,此版本包含了该修复。

xurqigkl

xurqigkl2#

CC @randall77@cuiweixie

vlurs2pr

vlurs2pr3#

这个错误似乎是很难复现的。

$x_{1}a_{0}b_{1}x$

vm0i2vca

vm0i2vca4#

@cuiweixie: are you sure it is actually running the test? On my machine (Apple M1), it can only do a couple hundred runs per 5s:

# go test ./vfs -run TestMapClone -exec 'stress -p 10' -v
194 runs so far, 0 failures, over 5s
405 runs so far, 0 failures, over 10s
^C559 runs completed, 0 failures, over 14s

P.S. A friendly request - please don't post long irrelevant backtraces, it makes the issue hard to navigate. E.g. it would have been sufficient to post just 11m0s: 433534 runs so far, 0 failures, 10 active .

w46czmvw

w46czmvw5#

对不起,我更改了迭代次数!
重新运行!

yx2lnoni

yx2lnoni6#

它花了大约7分钟才崩溃。但我现在再试一次,11分钟内没有崩溃。可能需要很长时间。
请注意,在 cockroachdb/pebble#3894 中,我们看到了地址0( signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0x417278] )上的故障。查看代码,我不认为这是如何发生的,除非源指针被损坏并且接近uint64的末尾范围,导致我们在访问时发生溢出。

rjee0c15

rjee0c157#

我正在运行你的代码!
请勿复制!很悲伤!

➜  issue69110 git:(go1.22.5) ✗ go test -v . -run="TestMapClone" -exec "stress -p 10"
5s: 218 runs so far, 0 failures, 10 active
10s: 464 runs so far, 0 failures, 10 active
15s: 688 runs so far, 0 failures, 10 active
20s: 893 runs so far, 0 failures, 10 active
25s: 1113 runs so far, 0 failures, 10 active
30s: 1344 runs so far, 0 failures, 10 active
35s: 1585 runs so far, 0 failures, 10 active
40s: 1829 runs so far, 0 failures, 10 active
45s: 2067 runs so far, 0 failures, 10 active
50s: 2309 runs so far, 0 failures, 10 active
55s: 2551 runs so far, 0 failures, 10 active
1m0s: 2769 runs so far, 0 failures, 10 active
1m5s: 2968 runs so far, 0 failures, 10 active
1m10s: 3176 runs so far, 0 failures, 10 active
1m15s: 3415 runs so far, 0 failures, 10 active
1m20s: 3653 runs so far, 0 failures, 10 active
1m25s: 3892 runs so far, 0 failures, 10 active
1m30s: 4122 runs so far, 0 failures, 10 active
1m35s: 4338 runs so far, 0 failures, 10 active
1m40s: 4555 runs so far, 0 failures, 10 active
1m45s: 4779 runs so far, 0 failures, 10 active
1m50s: 5006 runs so far, 0 failures, 10 active
1m55s: 5216 runs so far, 0 failures, 10 active
2m0s: 5435 runs so far, 0 failures, 10 active
2m5s: 5668 runs so far, 0 failures, 10 active
2m10s: 5899 runs so far, 0 failures, 10 active
2m15s: 6092 runs so far, 0 failures, 10 active
2m20s: 6317 runs so far, 0 failures, 10 active
2m25s: 6553 runs so far, 0 failures, 10 active
2m30s: 6793 runs so far, 0 failures, 10 active
2m35s: 7036 runs so far, 0 failures, 10 active
2m40s: 7253 runs so far, 0 failures, 10 active
2m45s: 7481 runs so far, 0 failures, 10 active
2m50s: 7727 runs so far, 0 failures, 10 active
2m55s: 7972 runs so far, 0 failures, 10 active
3m0s: 8217 runs so far, 0 failures, 10 active
3m5s: 8467 runs so far, 0 failures, 10 active
3m10s: 8711 runs so far, 0 failures, 10 active
3m15s: 8955 runs so far, 0 failures, 10 active
3m20s: 9203 runs so far, 0 failures, 10 active
3m25s: 9448 runs so far, 0 failures, 10 active
3m30s: 9695 runs so far, 0 failures, 10 active
3m35s: 9938 runs so far, 0 failures, 10 active
3m40s: 10184 runs so far, 0 failures, 10 active
3m45s: 10430 runs so far, 0 failures, 10 active
3m50s: 10674 runs so far, 0 failures, 10 active
3m55s: 10923 runs so far, 0 failures, 10 active
4m0s: 11170 runs so far, 0 failures, 10 active
4m5s: 11413 runs so far, 0 failures, 10 active
4m10s: 11616 runs so far, 0 failures, 10 active
4m15s: 11833 runs so far, 0 failures, 10 active
4m20s: 12047 runs so far, 0 failures, 10 active
4m25s: 12243 runs so far, 0 failures, 10 active
4m30s: 12418 runs so far, 0 failures, 10 active
4m35s: 12547 runs so far, 0 failures, 10 active
4m40s: 12712 runs so far, 0 failures, 10 active
4m45s: 12917 runs so far, 0 failures, 10 active
4m50s: 13143 runs so far, 0 failures, 10 active
4m55s: 13388 runs so far, 0 failures, 10 active
5m0s: 13635 runs so far, 0 failures, 10 active
5m5s: 13877 runs so far, 0 failures, 10 active
5m10s: 14091 runs so far, 0 failures, 10 active
5m15s: 14335 runs so far, 0 failures, 10 active
5m20s: 14582 runs so far, 0 failures, 10 active
5m25s: 14829 runs so far, 0 failures, 10 active
5m30s: 15078 runs so far, 0 failures, 10 active
5m35s: 15321 runs so far, 0 failures, 10 active
5m40s: 15566 runs so far, 0 failures, 10 active
5m45s: 15808 runs so far, 0 failures, 10 active
5m50s: 16051 runs so far, 0 failures, 10 active
5m55s: 16296 runs so far, 0 failures, 10 active
6m0s: 16544 runs so far, 0 failures, 10 active
6m5s: 16784 runs so far, 0 failures, 10 active
6m10s: 17029 runs so far, 0 failures, 10 active
6m15s: 17269 runs so far, 0 failures, 10 active
6m20s: 17499 runs so far, 0 failures, 10 active
6m25s: 17744 runs so far, 0 failures, 10 active
6m30s: 17992 runs so far, 0 failures, 10 active
6m35s: 18235 runs so far, 0 failures, 10 active
6m40s: 18482 runs so far, 0 failures, 10 active
6m45s: 18722 runs so far, 0 failures, 10 active
6m50s: 18970 runs so far, 0 failures, 10 active
6m55s: 19217 runs so far, 0 failures, 10 active
7m0s: 19462 runs so far, 0 failures, 10 active
7m5s: 19705 runs so far, 0 failures, 10 active
7m10s: 19930 runs so far, 0 failures, 10 active
7m15s: 20170 runs so far, 0 failures, 10 active
7m20s: 20419 runs so far, 0 failures, 10 active
7m25s: 20664 runs so far, 0 failures, 10 active
7m30s: 20899 runs so far, 0 failures, 10 active
7m35s: 21138 runs so far, 0 failures, 10 active
7m40s: 21382 runs so far, 0 failures, 10 active
7m45s: 21627 runs so far, 0 failures, 10 active
7m50s: 21871 runs so far, 0 failures, 10 active
7m55s: 22116 runs so far, 0 failures, 10 active
8m0s: 22363 runs so far, 0 failures, 10 active
8m5s: 22609 runs so far, 0 failures, 10 active
8m10s: 22857 runs so far, 0 failures, 10 active
8m15s: 23101 runs so far, 0 failures, 10 active
8m20s: 23312 runs so far, 0 failures, 10 active
8m25s: 23560 runs so far, 0 failures, 10 active
8m30s: 23802 runs so far, 0 failures, 10 active
8m35s: 24048 runs so far, 0 failures, 10 active
8m40s: 24290 runs so far, 0 failures, 10 active
8m45s: 24507 runs so far, 0 failures, 10 active
8m50s: 24741 runs so far, 0 failures, 10 active
8m55s: 24988 runs so far, 0 failures, 10 active
9m0s: 25233 runs so far, 0 failures, 10 active
9m5s: 25477 runs so far, 0 failures, 10 active
9m10s: 25722 runs so far, 0 failures, 10 active
9m15s: 25960 runs so far, 0 failures, 10 active
9m20s: 26202 runs so far, 0 failures, 10 active
9m25s: 26430 runs so far, 0 failures, 10 active
9m30s: 26647 runs so far, 0 failures, 10 active
9m35s: 26838 runs so far, 0 failures, 10 active
9m40s: 27073 runs so far, 0 failures, 10 active
9m45s: 27287 runs so far, 0 failures, 10 active
9m50s: 27536 runs so far, 0 failures, 10 active
9m55s: 27777 runs so far, 0 failures, 10 active
10m0s: 28025 runs so far, 0 failures, 10 active
10m5s: 28267 runs so far, 0 failures, 10 active
10m10s: 28479 runs so far, 0 failures, 10 active
10m15s: 28709 runs so far, 0 failures, 10 active
10m20s: 28950 runs so far, 0 failures, 10 active
10m25s: 29193 runs so far, 0 failures, 10 active
10m30s: 29438 runs so far, 0 failures, 10 active
10m35s: 29678 runs so far, 0 failures, 10 active
10m40s: 29921 runs so far, 0 failures, 10 active
10m45s: 30158 runs so far, 0 failures, 10 active
10m50s: 30401 runs so far, 0 failures, 10 active
10m55s: 30645 runs so far, 0 failures, 10 active
xn1cxnb4

xn1cxnb48#

这可能需要一段时间,我会将超时时间增加到例如1小时。我在不同版本的测试上运行了多次,直到我看到崩溃,所以它可能是一个特别幸运的运行。

相关问题