mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-25 08:09:07 +02:00
Make the VNC server single-use and recognise crash-leftover desktop processes by their recorded command
This commit is contained in:
@@ -681,44 +681,23 @@ func TestCloseAdmission_RefusesAndDrains(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCloseAdmission_HandlerOutlivingDrain reproduces the restart hazard: Stop
|
||||
// gives up after handlerDrainTimeout, so a handler can still be running when a
|
||||
// later Start reopens admission. The counter must survive that (a sync.WaitGroup
|
||||
// panics on an Add racing the Wait it left behind), and the next Stop must wait
|
||||
// for both the straggler and the handlers admitted after the restart.
|
||||
func TestCloseAdmission_HandlerOutlivingDrain(t *testing.T) {
|
||||
srv := &Server{log: log.WithField("test", t.Name())}
|
||||
// A Server is single-use. Stop closes the listener, capturer and injector it was
|
||||
// handed and cannot recreate, so a second Start would accept on a closed socket
|
||||
// and capture from a closed display. It must be refused instead.
|
||||
func TestStart_AfterStopIsRejected(t *testing.T) {
|
||||
srv := New(Config{
|
||||
Capturer: &StubCapturer{},
|
||||
Injector: &StubInputInjector{},
|
||||
DisableAuth: true,
|
||||
})
|
||||
addr := netip.MustParseAddrPort("127.0.0.1:0")
|
||||
network := netip.MustParsePrefix("127.0.0.0/8")
|
||||
|
||||
require.True(t, srv.beginHandler())
|
||||
firstDrain := srv.closeAdmission()
|
||||
select {
|
||||
case <-firstDrain:
|
||||
t.Fatal("drained while a handler was still in flight")
|
||||
default:
|
||||
}
|
||||
require.NoError(t, srv.Start(t.Context(), addr, network))
|
||||
require.NoError(t, srv.Stop())
|
||||
|
||||
// What Start does after a drain that timed out.
|
||||
srv.handlersMu.Lock()
|
||||
srv.stopping = false
|
||||
srv.handlersDrained = nil
|
||||
srv.handlersMu.Unlock()
|
||||
|
||||
require.True(t, srv.beginHandler(), "a restarted server must admit handlers again")
|
||||
|
||||
secondDrain := srv.closeAdmission()
|
||||
srv.endHandler() // the straggler from before the restart
|
||||
select {
|
||||
case <-secondDrain:
|
||||
t.Fatal("drained before the post-restart handler finished")
|
||||
default:
|
||||
}
|
||||
|
||||
srv.endHandler()
|
||||
select {
|
||||
case <-secondDrain:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("drain signal never fired after restart")
|
||||
}
|
||||
err := srv.Start(t.Context(), addr, network)
|
||||
require.ErrorIs(t, err, errServerStopped, "a stopped server must not start again")
|
||||
}
|
||||
|
||||
func TestAcceptRetryable(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user