Skip to content

Commit 8bf94b9

Browse files
aykevldeadprogram
authored andcommitted
internal/task: disallow blocking inside an interrupt
Blocking inside an interrupt is always unsafe and will lead to all kinds of bad behavior (even if it might appear to work sometimes). So disallow it, just like allocating heap memory inside an interrupt is not allowed. I suspect this will usually be caused by channel sends, like this: ch <- someValue The easy workaround is to make it a non-blocking send instead: select { case ch <- someValue: default: } This does mean the application might become a bit more complex to be able to deal with this case, but the alternative (undefined behavior) is IMHO much worse.
1 parent 4881747 commit 8bf94b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/internal/task/task_stack.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
package task
44

5-
import "unsafe"
5+
import (
6+
"runtime/interrupt"
7+
"unsafe"
8+
)
69

710
//go:linkname runtimePanic runtime.runtimePanic
811
func runtimePanic(str string)
@@ -45,6 +48,9 @@ func Pause() {
4548
if *currentTask.state.canaryPtr != stackCanary {
4649
runtimePanic("goroutine stack overflow")
4750
}
51+
if interrupt.In() {
52+
runtimePanic("blocked inside interrupt")
53+
}
4854
currentTask.state.pause()
4955
}
5056

0 commit comments

Comments
 (0)