go: runtime: TestGdbCoreCrashThreadBacktrace failures

#!watchflakes
post <- pkg == "runtime" && test == "TestGdbCoreCrashThreadBacktrace"

Issue created automatically to collect these failures.

Example (log):

--- FAIL: TestGdbCoreCrashThreadBacktrace (7.67s)
    runtime-gdb_test.go:81: gdb version 10.1
    runtime-gdb_unix_test.go:334: child output:
        Setting RLIMIT_CORE = syscall.Rlimit{Cur:0xffffffffffffffff, Max:0xffffffffffffffff}
        SIGSEGV: segmentation violation
        PC=0x48cc65 m=0 sigcode=1 addr=0x0
        signal arrived during cgo execution

        goroutine 1 gp=0xc0000081c0 m=0 mp=0x548740 [syscall]:
        runtime.cgocall(0x48cc6e, 0xc00006ff20)
...
        #19 0x000000000043b076 in runtime.mstart0 () at /workdir/go/src/runtime/proc.go:1684
        #20 0x0000000000462c65 in runtime.mstart () at /workdir/go/src/runtime/asm_amd64.s:394
        #21 0x000000000048d669 in crosscall1 () at gcc_amd64.S:42
        #22 0x0000000000802000 in ?? ()
        #23 0x00007f8b74b75fc0 in ?? ()
        #24 0x00007ffd0d4c302f in ?? ()
        #25 0x000000c000008a80 in ?? ()
        #26 0x0000000000462c60 in ?? ()
        #27 0x0000000000000000 in ?? ()
    runtime-gdb_unix_test.go:375: could not find trigger_crash in backtrace

— watchflakes

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the analysis @bcmills! I agree with you, this looks like a genuine race condition. It is also note new in https://go.dev/cl/536895, it appears to have ~always existed (https://go.dev/cl/245018 extended the race window, but it was present before that too).

Regarding a fix, I’ll need to think some more. I’m not thrilled about masking signals, but I don’t have a better idea at the moment.

I could imagine this causing some of those other crashes, but not all. e.g., #60316: I don’t see how this could manifest as a SIGCHLD death.

Since this bug isn’t new, fixing it need not block the release, but we should still do something about the test. Should we mark it flaky until this bug is fixed?

Yep, I agree that a testenv.SkipFlaky in the new test would be fine to unblock the Go 1.22 release.

Some analysis of the test log reported by watchflakes.

The program ends up running six goroutines in total. When run on my workstation, at the time of the crash the goroutines are parked in the following locations:

In a successful run on my local workstation, I see SIGQUIT: quit logs for five background threads:

In the builder log, we see SIGQUIT: quit logs for only four background threads:

  • one in notetsleep via sysmon (as expected)
  • one in notesleep via templateThread (as expected)
  • one in allocm via schedule, resetspinning, and newm
  • one in stopm via schedule and startlockedm

The thread in allocm looks suspiciously like a race in the runtime. In particular:

  • startm calls mReserveID (incrementing mnext) before it calls newm
  • The newm thread was interrupted by SIGQUIT during allocm, which is before the new thread is actually started for the M (in newm1).

So this looks like a genuine watchdog failure: the kernel defers delivery of the final SIGQUIT signal because all of the threads that could receive it are already handling a SIGQUIT (with that signal presumably masked), and the main thread is spinning in the docrash loop waiting for acknowledgement from a fifth thread that had an M ID reserved but was never actually started.

Perhaps startm needs to block signals from at some point before calling mReserveID until newm has returned?

It would usually spend at least 500ms(per loop) to quit when crash, kind of slower compared to 1.21 or earier releases(like sticking in somewhere for a very few moment while waiting the first thread to crash).

This is a good point. This is an effect of https://cs.opensource.google/go/go/+/master:src/runtime/signal_unix.go;l=781;drc=de5b418bea70aaf27de1f47e9b5813940d1e15a4. The crashing thread will almost certainly sleep for 500ms at least once while waiting for SIGQUIT to make its rounds. IMO, we should just reduce this is something small, like 1ms, as it shouldn’t take long for other threads to exit.

Actually, a better theory: usleep doesn’t loop on early return of the nanosleep syscall (e.g., if another signal is delivered), so it could return in <5s. We should really fix that.