Skip to content

Commit ad792e2

Browse files
committed
intra: m Crash runtime on demand
1 parent 5ba1b8c commit ad792e2

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

intra/tun2socks.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"context"
2828
"os"
2929
"runtime/debug"
30+
"time"
3031

3132
x "github.com/celzero/firestack/intra/backend"
3233
"github.com/celzero/firestack/intra/core"
@@ -300,6 +301,16 @@ func PanicAtRandom(y bool) {
300301
log.I("tun: panic at random? %t", y)
301302
}
302303

304+
// Crash causes a crash by panicking on an out-of-bounds slice access. For testing only.
305+
func Crash(afterMs int64) {
306+
go func() {
307+
log.I("tun: crashing in %s", core.FmtMillis(afterMs))
308+
time.Sleep(time.Duration(afterMs) * time.Millisecond)
309+
var i []int
310+
i[10] = 1 // panic: runtime error: index out of range [10] with length 10
311+
}()
312+
}
313+
303314
func pipeCrashOutput(c Console) (ok bool) {
304315
r, w, err := os.Pipe()
305316
if err != nil {

0 commit comments

Comments
 (0)