Skip to content

Commit

Permalink
Make termination of Buildbarn binaries a bit more reliable
Browse files Browse the repository at this point in the history
If a Buildbarn binary is launched as part of a process group and is not
the process group leader, it may be the case that it receives signals
delivered to the process group which are ignored by the process itself.
This causes our final termination signal to never arrive.

Let's put a safety belt in place, calling os.Exit() if a sufficient
amount of time passes.
  • Loading branch information
EdSchouten committed Aug 9, 2024
1 parent 24d544b commit 02b8a19
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/program/run_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/signal"
"sync"
"syscall"
"time"
)

// runMainErrorLogger is used by RunMain() to capture errors returned by
Expand Down Expand Up @@ -73,12 +74,23 @@ func RunMain(routine Routine) {
if err := process.Signal(receivedSignal); err != nil {
panic(err)
}

// This code should not be reached, if it
// weren't for the fact that process.Signal()
// does not guarantee that the signal is
// delivered to the same thread. More details:
// delivered to the same thread.
//
// Furthermore, signal.Reset() does not reset
// signals that are delivered via the process
// group, but ignored by the process itself.
// Fall back to calling os.Exit() if we don't
// get terminated via signal delivery.
//
// More details:
// https://github.com/golang/go/issues/19326
select {}
// https://github.com/golang/go/issues/46321
time.Sleep(5)
os.Exit(1)
})
}()

Expand Down

0 comments on commit 02b8a19

Please sign in to comment.