Skip to content

runtime/debug: SetMaxThreads(maxInt) crashes program with "-1-thread limit" #16076

@bcmills

Description

@bcmills
$ go version
go version go1.6.1 linux/amd64

According to https://golang.org/pkg/runtime/debug/#SetMaxThreads, this program should be able to spawn essentially as many threads as it wants:

$ cat maxthreads/maxthreads.go
package main

import (
        "fmt"
        "runtime/debug"
)

func main() {
        const maxInt = int(^uint(0) >> 1)
        fmt.Println(maxInt)
        debug.SetMaxThreads(maxInt)
}

Instead, the runtime kills it immediately:

$ go run maxthreads/maxthreads.go
9223372036854775807
runtime: program exceeds -1-thread limit
fatal error: thread exhaustion

goroutine 1 [running]:
runtime.throw(0x518650, 0x11)
        /usr/lib/google-golang/src/runtime/panic.go:550 +0x99 fp=0xc820043e90 sp=0xc820043e78 pc=0x4289c9
runtime.checkmcount()
        /usr/lib/google-golang/src/runtime/proc.go:483 +0x94 fp=0xc820043eb0 sp=0xc820043e90 pc=0x42b5a4
runtime/debug.setMaxThreads(0x7fffffffffffffff, 0x2710)
        /usr/lib/google-golang/src/runtime/proc.go:4180 +0x46 fp=0xc820043ec0 sp=0xc820043eb0 pc=0x435b96
runtime/debug.SetMaxThreads(0x7fffffffffffffff, 0x1)
        /usr/lib/google-golang/src/runtime/debug/garbage.go:140 +0x21 fp=0xc820043ed8 sp=0xc820043ec0 pc=0x469581
main.main()
        /usr/local/google/home/bcmills/src/maxthreads/maxthreads.go:11 +0xd9 fp=0xc820043f50 sp=0xc820043ed8 pc=0x4010d9
runtime.main()
        /usr/lib/google-golang/src/runtime/proc.go:188 +0x2b0 fp=0xc820043fa0 sp=0xc820043f50 pc=0x42a160
runtime.goexit()
        /usr/lib/google-golang/src/runtime/asm_amd64.s:2002 +0x1 fp=0xc820043fa8 sp=0xc820043fa0 pc=0x4577b1
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions