Send SIGQUIT when cancelling an execution
When the context passed to Nomad Allocation Exec is cancelled, the process is not terminated. Instead, just the WebSocket connection is closed. In order to terminate long-running processes, a special character is injected into the standard input stream. This character is parsed by the tty line discipline (tty has to be true). The line discipline sends a SIGQUIT signal to the process, terminating it and producing a core dump (in a file called 'core'). The SIGQUIT signal can be caught but isn't by default, which is why the runner is destroyed if the program does not terminate during a grace period after the signal was sent.
This commit is contained in:
24
pkg/nullio/nullio.go
Normal file
24
pkg/nullio/nullio.go
Normal file
@ -0,0 +1,24 @@
|
||||
package nullio
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Reader is a struct that implements the io.Reader interface. Read does not return when called.
|
||||
type Reader struct{}
|
||||
|
||||
func (r Reader) Read(_ []byte) (int, error) {
|
||||
// An empty select blocks forever.
|
||||
select {}
|
||||
}
|
||||
|
||||
// ReadWriter implements io.ReadWriter and does nothing on Read an Write.
|
||||
type ReadWriter struct {
|
||||
Reader
|
||||
}
|
||||
|
||||
func (nrw *ReadWriter) Write(p []byte) (int, error) {
|
||||
n, err := io.Discard.Write(p)
|
||||
return n, fmt.Errorf("error writing to io.Discard: %w", err)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package nullreader
|
||||
package nullio
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -9,8 +9,8 @@ import (
|
||||
|
||||
const shortTimeout = 100 * time.Millisecond
|
||||
|
||||
func TestNullReaderDoesNotReturnImmediately(t *testing.T) {
|
||||
reader := &NullReader{}
|
||||
func TestReaderDoesNotReturnImmediately(t *testing.T) {
|
||||
reader := &Reader{}
|
||||
readerReturned := make(chan bool)
|
||||
go func() {
|
||||
p := make([]byte, 0, 5)
|
@ -1,10 +0,0 @@
|
||||
package nullreader
|
||||
|
||||
// NullReader is a struct that implements the io.Reader interface and returns nothing when reading
|
||||
// from it.
|
||||
type NullReader struct{}
|
||||
|
||||
func (r NullReader) Read(_ []byte) (int, error) {
|
||||
// An empty select blocks forever.
|
||||
select {}
|
||||
}
|
Reference in New Issue
Block a user