Skip to content

runtime: "sweep increased allocation count" when using reflect.Call #21717

Closed
@g7r

Description

@g7r

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

go version go1.8.3 darwin/amd64, go version go1.9 darwin/amd64 and go version go1.8.3 linux/amd64 (i. e. all I've tried)

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sz/src/gohome"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9h/x_80x8ln3_g038_zj_t9tszw0000gn/T/go-build347957070=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package main

import "reflect"

func main() {
	fv := reflect.ValueOf(func(int) struct{} { return struct{}{} })
	args := []reflect.Value{reflect.ValueOf(0)}

	for {
		fv.Call(args)
	}
}

What did you expect to see?

Infinite loop

What did you see instead?

Crash with message fatal error: sweep increased allocation count within a second or less

runtime: nelems=512 nalloc=16 previous allocCount=15 nfreed=65535
fatal error: sweep increased allocation count

runtime stack:
runtime.throw(0x10a64a6, 0x20)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/panic.go:605 +0x95
runtime.(*mspan).sweep(0x11be000, 0x11be001, 0x0)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/mgcsweep.go:298 +0x911
runtime.(*mcentral).cacheSpan(0x1116af0, 0x110ed90)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/mcentral.go:58 +0x2cd
runtime.(*mcache).refill(0x114d000, 0x102d405, 0xc420000a80)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/mcache.go:123 +0xa4
runtime.(*mcache).nextFree.func1()
        /usr/local/Cellar/go/1.9/libexec/src/runtime/malloc.go:557 +0x32
runtime.systemstack(0xc420020000)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/asm_amd64.s:344 +0x79
runtime.mstart()
        /usr/local/Cellar/go/1.9/libexec/src/runtime/proc.go:1125

goroutine 1 [running]:
runtime.systemstack_switch()
        /usr/local/Cellar/go/1.9/libexec/src/runtime/asm_amd64.s:298 fp=0xc420045a68 sp=0xc420045a60 pc=0x104bec0
runtime.(*mcache).nextFree(0x114d000, 0x5, 0xc420045b78, 0x100e5f0, 0xc4202f23a0)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/malloc.go:556 +0xa9 fp=0xc420045ac0 sp=0xc420045a68 pc=0x100df19
runtime.mallocgc(0x8, 0xc42007a0f0, 0x100f401, 0xc42007a0f0)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/malloc.go:687 +0x5c2 fp=0xc420045b68 sp=0xc420045ac0 pc=0x100e6b2
runtime.newobject(0xc42007a0f0, 0xc42000a080)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/malloc.go:840 +0x38 fp=0xc420045b98 sp=0xc420045b68 pc=0x100eb28
reflect.unsafe_New(0xc42007a0f0, 0x0)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/malloc.go:845 +0x2b fp=0xc420045bb8 sp=0xc420045b98 pc=0x100eb7b
reflect.Value.call(0x108bce0, 0x10a86a8, 0x13, 0x10a2ce7, 0x4, 0xc420045f58, 0x1, 0x1, 0xc4202f23a0, 0x1, ...)
        /usr/local/Cellar/go/1.9/libexec/src/reflect/value.go:408 +0xcbe fp=0xc420045e90 sp=0xc420045bb8 pc=0x1069a1e
reflect.Value.Call(0x108bce0, 0x10a86a8, 0x13, 0xc420045f58, 0x1, 0x1, 0xc4202f23a0, 0x1, 0x1)
        /usr/local/Cellar/go/1.9/libexec/src/reflect/value.go:302 +0xa4 fp=0xc420045ef8 sp=0xc420045e90 pc=0x1068c44
main.main()
        /Users/sz/src/gohome/src/github.com/joomcode/api/junk/sz/joom-go-sweep-treat/main.go:10 +0xd6 fp=0xc420045f80 sp=0xc420045ef8 pc=0x1078476
runtime.main()
        /usr/local/Cellar/go/1.9/libexec/src/runtime/proc.go:185 +0x20d fp=0xc420045fe0 sp=0xc420045f80 pc=0x1026ebd
runtime.goexit()
        /usr/local/Cellar/go/1.9/libexec/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420045fe8 sp=0xc420045fe0 pc=0x104e511
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions