mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: handle SIGHUP from OpenSSH (#10638)
Fixes an issue where remote forwards are not correctly torn down when using OpenSSH with `coder ssh --stdio`. OpenSSH sends a disconnect signal, but then also sends SIGHUP to `coder`. Previously, we just exited when we got SIGHUP, and this raced against properly disconnecting. Fixes https://github.com/coder/customers/issues/327
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package clitest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type FakeSignalNotifier struct {
|
||||
sync.Mutex
|
||||
t *testing.T
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
signals []os.Signal
|
||||
stopped bool
|
||||
}
|
||||
|
||||
func NewFakeSignalNotifier(t *testing.T) *FakeSignalNotifier {
|
||||
fsn := &FakeSignalNotifier{t: t}
|
||||
return fsn
|
||||
}
|
||||
|
||||
func (f *FakeSignalNotifier) Stop() {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
f.stopped = true
|
||||
if f.cancel == nil {
|
||||
f.t.Error("stopped before started")
|
||||
return
|
||||
}
|
||||
f.cancel()
|
||||
}
|
||||
|
||||
func (f *FakeSignalNotifier) NotifyContext(parent context.Context, signals ...os.Signal) (ctx context.Context, stop context.CancelFunc) {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
f.signals = signals
|
||||
f.ctx, f.cancel = context.WithCancel(parent)
|
||||
return f.ctx, f.Stop
|
||||
}
|
||||
|
||||
func (f *FakeSignalNotifier) Notify() {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
if f.cancel == nil {
|
||||
f.t.Error("notified before started")
|
||||
return
|
||||
}
|
||||
f.cancel()
|
||||
}
|
||||
|
||||
func (f *FakeSignalNotifier) AssertStopped() {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
assert.True(f.t, f.stopped)
|
||||
}
|
||||
Reference in New Issue
Block a user