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/debug: SetMaxThreads(maxInt) crashes program with "-1-thread limit" #16076

Closed
bcmills opened this issue Jun 15, 2016 · 4 comments
Closed

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

bcmills opened this issue Jun 15, 2016 · 4 comments

Comments

@bcmills
Copy link
Member

@bcmills bcmills commented Jun 15, 2016

$ 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
@bcmills
Copy link
Member Author

@bcmills bcmills commented Jun 15, 2016

(See also issue #4056.)

@bcmills
Copy link
Member Author

@bcmills bcmills commented Jun 15, 2016

The same program works fine with int(^uint32(0) >> 1) as a workaround, but the arbitrary 32-bit limit is surprising when I'm trying to write a call that says "let me use as many threads as I want".

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 16, 2016

This is because of this line in proc.go:

sched.maxmcount = int32(in)

We could change all the variables from int32 to int, or, probably just as good in practice, use the maximum int32 value here if the argument to setMaxThreads is larger.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 16, 2016
@quentinmit quentinmit added the NeedsFix label Oct 10, 2016
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 20, 2016

CL https://golang.org/cl/31516 mentions this issue.

@gopherbot gopherbot closed this in 10560af Oct 20, 2016
@golang golang locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants