Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: mallocgc give "span has no free objects" #44082

Open
stupidjohn opened this issue Feb 3, 2021 · 6 comments
Open

runtime: mallocgc give "span has no free objects" #44082

stupidjohn opened this issue Feb 3, 2021 · 6 comments

Comments

@stupidjohn
Copy link

@stupidjohn stupidjohn commented Feb 3, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15.6 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env


GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zhuoyikang/.cache/go-build"
GOENV="/home/zhuoyikang/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zhuoyikang/Go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zhuoyikang/Go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/zhuoyikang/GoSDK/go1.15.6"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/zhuoyikang/GoSDK/go1.15.6/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build665856385=/tmp/go-build -gno-record-gcc-switches"

What did you do?

we make a map by units = make(map[int32]*Struct), and then insert it, golang panic out with "span has no free objects". looks like mcentral give a full span when it should give a partial full one.

What did you expect to see?

program run with no problem.

What did you see instead?

panic with

7455-fatal error: span has no free objects
7456-
7457-goroutine 3039 [running]:
7458-runtime.throw(0x34bbb0b, 0x18)
7459:   /home/ubuntu/go/go1.15.6/src/runtime/panic.go:1116 +0x72 fp=0xc05ac7e398 sp=0xc05ac7e368 pc=0x4397f2
7460-runtime.(*mcentral).cacheSpan(0x50384d8, 0x7f94aa1e7080)
7461-   /home/ubuntu/go/go1.15.6/src/runtime/mcentral.go:189 +0x44c fp=0xc05ac7e410 sp=0xc05ac7e398 pc=0x41ab8c
7462-runtime.(*mcache).refill(0x7f94e9888560, 0x10)
7463-   /home/ubuntu/go/go1.15.6/src/runtime/mcache.go:142 +0xa5 fp=0xc05ac7e430 sp=0xc05ac7e410 pc=0x41a4c5
7464-runtime.(*mcache).nextFree(0x7f94e9888560, 0x322d610, 0x0, 0x0, 0x7f94a9da3318)
7465-   /home/ubuntu/go/go1.15.6/src/runtime/malloc.go:880 +0x8d fp=0xc05ac7e468 sp=0xc05ac7e430 pc=0x40f5ed
7466-runtime.mallocgc(0x70, 0x309e4a0, 0x4dd9b9a0a93bfb01, 0x19)
7467-   /home/ubuntu/go/go1.15.6/src/runtime/malloc.go:1061 +0x834 fp=0xc05ac7e508 sp=0xc05ac7e468 pc=0x40ffd4
7468-runtime.newobject(...)
7469-   /home/ubuntu/go/go1.15.6/src/runtime/malloc.go:1195
7470-runtime.mapassign_fast32(0x2f7c6e0, 0xc0470e4d80, 0xc00000000d, 0x3)
7471-   /home/ubuntu/go/go1.15.6/src/runtime/map_fast32.go:109 +0x2d5 fp=0xc05ac7e548 sp=0xc05ac7e508 pc=0x413f15
7472-oops/common/massmap.getNpcUnitsCfg(0x38a9540, 0xc029f7d810, 0xc029f7d810)
7473-   /home/ubuntu/workplace_ci/src/oops/common/massmap/unit.go:810 +0x145 fp=0xc05ac7e5a8 sp=0xc05ac7e548 pc=0x24abbc5
7474-oops/common/massmap.getNpcUniCfgBuff(...)
7475-   /home/ubuntu/workplace_ci/src/oops/common/massmap/unit.go:676
7476-oops/common/massmap.(*AttackUnit).calcBaseHP(0xc042c472c0, 0x4073333333333333)
7477-   /home/ubuntu/workplace_ci/src/oops/common/massmap/unit.go:383 +0x8d fp=0xc05ac7e660 sp=0xc05ac7e5a8 pc=0x24a93ad
7478-oops/common/massmap.(*AttackTroop).AttackUnits(0xc042c46b90)
7479-   /home/ubuntu/workplace_ci/src/oops/common/massmap/troop.go:969 +0x12d fp=0xc05ac7e720 sp=0xc05ac7e660 pc=0x24a042d
7480-oops/common/massmap.(*Troops).AttackTroop(0xc03c9444b0, 0x38a9540, 0xc029f7d810, 0x38ab420, 0xc0002a6000, 0x2)
7481-   /home/ubuntu/workplace_ci/src/oops/common/massmap/troop.go:1422 +0x18c fp=0xc05ac7e7a8 sp=0xc05ac7e720 pc=0x24a318c
7482-oops/common/massmap.(*MapBase).doNormalAttack(0xc0002a6000, 0x38a9540, 0xc0461b4160, 0x38a9540, 0xc029f7d810, 0xc0002a6170)
7483-   /home/ubuntu/workplace_ci/src/oops/common/massmap/attack.go:1819 +0x309 fp=0xc05ac7e930 sp=0xc05ac7e7a8 pc=0x2209509
7484-oops/common/massmap.(*MapBase).doAttack(0xc0002a6000, 0x38a9540, 0xc0461b4160, 0x38a9540, 0xc029f7d810, 0xc0002a6170, 0x800000008)
7485-   /home/ubuntu/workplace_ci/src/oops/common/massmap/attack.go:2261 +0x2d7 fp=0xc05ac7e990 sp=0xc05ac7e930 pc=0x220c1d7
7486-oops/common/massmap.(*MapBase).AttackPhase.func2(0x38a9540, 0xc0461b4160)
7487-   /home/ubuntu/workplace_ci/src/oops/common/massmap/mapbase.go:909 +0x199 fp=0xc05ac7ea38 sp=0xc05ac7e990 pc=0x25181d9
7488-oops/common/massmap.(*LMap).Iter(0xc012966690, 0xc05ac7ecb0)
7489-   /home/ubuntu/workplace_ci/src/oops/common/massmap/mod_char.go:85 +0x193 fp=0xc05ac7eae8 sp=0xc05ac7ea38 pc=0x23518b3
7490-oops/common/massmap.(*MapBase).AttackPhase(0xc0002a6000, 0x1776660bdcd, 0x0)
7491-   /home/ubuntu/workplace_ci/src/oops/common/massmap/mapbase.go:980 +0x21f fp=0xc05ac7f248 sp=0xc05ac7eae8 pc=0x22ef6ff
7492-oops/common/massmap.(*MassMap).atkPhase(...)
7493-   /home/ubuntu/workplace_ci/src/oops/common/massmap/phase.go:80
7494-oops/common/massmap.(*MassMap).tickPhase(0xc015ef00a0, 0x1776660bdcd, 0xa5509, 0x3e8)
7495-   /home/ubuntu/workplace_ci/src/oops/common/massmap/context.go:772 +0x345 fp=0xc05ac7fd78 sp=0xc05ac7f248 pc=0x225ba25
7496-oops/common/massmap.(*MassMap).TickReq(0xc015ef00a0, 0xc0000a5509, 0x1776660bdcd, 0xc05ac7ff20)
7497-   /home/ubuntu/workplace_ci/src/oops/common/massmap/massmap.go:1841 +0x6b fp=0xc05ac7fdb0 sp=0xc05ac7fd78 pc=0x232524b
7498-oops/common/massmap.(*MassMapClient).TickReq.func1(0xc05c3a4700)
7499-   /home/ubuntu/workplace_ci/src/oops/common/massmap/client.go:1663 +0x74 fp=0xc05ac7fdf8 sp=0xc05ac7fdb0 pc=0x24ca834
7500-oops/common/massmap.(*MassMapClient).callOpt.func1()
7501-   /home/ubuntu/workplace_ci/src/oops/common/massmap/client.go:159 +0xac fp=0xc05ac7fe40 sp=0xc05ac7fdf8 pc=0x24bfeec
7502-oops/common/massmap.(*MassMap).Run.func1.1(0xc015ef00a0, 0xc00a343534)
7503-   /home/ubuntu/workplace_ci/src/oops/common/massmap/massmap.go:200 +0x307 fp=0xc05ac7ff88 sp=0xc05ac7fe40 pc=0x251ad47
7504-oops/common/massmap.(*MassMap).Run.func1(0xc015ef00a0, 0xc00a343534)
7505-   /home/ubuntu/workplace_ci/src/oops/common/massmap/massmap.go:221 +0xf0 fp=0xc05ac7ffd0 sp=0xc05ac7ff88 pc=0x251ae70
7506-runtime.goexit()
7507-   /home/ubuntu/go/go1.15.6/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc05ac7ffd8 sp=0xc05ac7ffd0 pc=0x472481
7508-created by oops/common/massmap.(*MassMap).Run
7509-   /home/ubuntu/workplace_ci/src/oops/common/massmap/massmap.go:179 +0xa5
7510-
7511-goroutine 1 [chan receive, 11286 minutes]:
7512-oops/gs/fm.(*GsGlobal).Loop(0x500fa80)
7513-   /home/ubuntu/workplace_ci/src/oops/gs/fm/gs_global.go:590 +0x4c
7514-main.main()
7515-   /home/ubuntu/workplace_ci/src/oops/gs/main.go:21 +0x18f
@stupidjohn stupidjohn changed the title mallocgc give "span has no free objects" runtime: mallocgc give "span has no free objects" Feb 3, 2021
@dreamerjackson
Copy link
Contributor

@dreamerjackson dreamerjackson commented Feb 3, 2021

do you have the full example?

@stupidjohn
Copy link
Author

@stupidjohn stupidjohn commented Feb 3, 2021

do you have the full example?

ok, it's really simple

units = make(map[int32]*gdd.PveUnitCsv)
var list []*gdd.PveUnitCsv= gdd.G.GetPveTroop(troopCfg.Troops)
for _, u := range list {
	units[u.UnitId] = u
}

the map is make and insert in getNpcUniCfgBuff func, and �return from it.

@randall77
Copy link
Contributor

@randall77 randall77 commented Feb 3, 2021

I think we're going to need a runnable example that demonstrates the problem if we're going to be able to fix it.

Does this happen all the time, or only occasionally?

Does running with the race detector (-race) report anything?

Does your program use unsafe anywhere?

@stupidjohn
Copy link
Author

@stupidjohn stupidjohn commented Feb 4, 2021

I think we're going to need a runnable example that demonstrates the problem if we're going to be able to fix it.

Does this happen all the time, or only occasionally?

Does running with the race detector (-race) report anything?

Does your program use unsafe anywhere?

hi, randall77. could you please explain how a data race could lead to allocator memory corruption? i could use the knowledge to troubleshoot the bug.
im afraid i could not offer a complete runable program to you, and we use no unsafe/unintptr in our code(except some lib like gogoprotobuf, uber zap etc).

@randall77
Copy link
Contributor

@randall77 randall77 commented Feb 4, 2021

hi, randall77. could you please explain how a data race could lead to allocator memory corruption? i could use the knowledge to troubleshoot the bug.

If your program has a data race, then all bets are off for the runtime executing your program correctly.
Data races can lead to the breaking of type safety (due to races on interface writes, among others), and that can lead to overwriting memory, including runtime data structures, which can lead to arbitrary crashes.

But of course the first thing to do is just run your program with -race and see what happens.

How about the other questions I asked?

@stupidjohn
Copy link
Author

@stupidjohn stupidjohn commented Feb 7, 2021

hi, randall77. could you please explain how a data race could lead to allocator memory corruption? i could use the knowledge to troubleshoot the bug.

If your program has a data race, then all bets are off for the runtime executing your program correctly.
Data races can lead to the breaking of type safety (due to races on interface writes, among others), and that can lead to overwriting memory, including runtime data structures, which can lead to arbitrary crashes.

But of course the first thing to do is just run your program with -race and see what happens.

How about the other questions I asked?

thank for give reference, we will check our code by this doc. if we cannot find & fix problem by ourself, we will take log here.

thanks for attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants