Skip to content

Commit a18f4fb

Browse files
committed
intra: test crash 2 console with exit
The behaviour of sending crash out to console differs between exit and non-exit scenarios. For example, log/memconsole does not flush synchronously, and so stands to miss out on crash logs, as exiting immediately after a caught panic will mean missed crash logs, if flush also hadn't happened on-path. This test now takes into account that scenario to make sure loggers do flush crash logs on-path.
1 parent e3c328f commit a18f4fb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

intra/tun2socks.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,17 @@ func PrintStack(where int32) []byte {
403403
}
404404

405405
// Crash causes a crash by panicking on an out-of-bounds slice access. For testing only.
406-
// Setting typ to 0 must send the crash output to stderr and abort, and 1 to console and not quit.
406+
// Setting typ to 0 must send the crash output to stderr and abort, and 1 to console and not quit,
407+
// while 2 must send the crash output to console and abort.
408+
// afterMs is the number of milliseconds to wait before crashing.
407409
func Crash(typ, afterMs int64) {
408410
go func() {
409-
if typ == 1 {
410-
defer core.Recover(core.DontExit, "tun: debugging... not a crash")
411+
if typ > 0 {
412+
exitcode := core.DontExit
413+
if typ == 2 {
414+
exitcode = core.Exit11
415+
}
416+
defer core.Recover(exitcode, "tun: debugging... not a crash")
411417
}
412418
log.I("tun: debug: crashing in %s", core.FmtMillis(afterMs))
413419
time.Sleep(time.Duration(afterMs) * time.Millisecond)

0 commit comments

Comments
 (0)