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: use exitGoroutine instead of deadlock #4647

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/runtime/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func panicOrGoexit(message interface{}, panicking panicState) {
}
}
if panicking == panicGoexit {
// Call to Goexit() instead of a panic.
// This is a call to Goexit() instead of a panic.
// Exit the goroutine instead of printing a panic message.
deadlock()
exitGoroutine()
}
printstring("panic: ")
printitf(message)
Expand Down
13 changes: 11 additions & 2 deletions src/runtime/scheduler_cooperative.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ var (
//
//go:noinline
func deadlock() {
// call yield without requesting a wakeup
exitGoroutine()
}

func exitGoroutine() {
// Pause the goroutine without a way for it to wake up.
// This makes the goroutine unreachable, and should eventually get it
// cleaned up by the GC.
task.Pause()
panic("unreachable")

// We will never return from task.Pause(). Make sure the compiler knows
// this.
trap()
}

// Add this task to the end of the run queue.
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/scheduler_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func deadlock() {
runtimePanic("all goroutines are asleep - deadlock!")
}

func exitGoroutine() {
// There is only one goroutine, which would exit, so that leads to a
// deadlock.
deadlock()
}

func scheduleTask(t *task.Task) {
// Pause() will panic, so this should not be reachable.
}
Expand Down
Loading