From 489a709abd26d0bad0868ff1bc7bc3b97c636d90 Mon Sep 17 00:00:00 2001 From: NHAS Date: Mon, 10 Jun 2024 17:41:41 +1200 Subject: [PATCH] Fix double close of channel --- internal/router/session_manager.go | 9 +++++++++ internal/router/statemachine.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/internal/router/session_manager.go b/internal/router/session_manager.go index 429b0d9..6b7f1d9 100644 --- a/internal/router/session_manager.go +++ b/internal/router/session_manager.go @@ -17,6 +17,8 @@ import ( type wsConnWrapper struct { *websocket.Conn wait chan interface{} + sync.Mutex + isClosed bool } func (ws *wsConnWrapper) Await() <-chan interface{} { @@ -24,6 +26,13 @@ func (ws *wsConnWrapper) Await() <-chan interface{} { } func (ws *wsConnWrapper) Close() error { + ws.Lock() + defer ws.Unlock() + + if ws.isClosed { + return nil + } + close(ws.wait) return ws.Conn.Close() } diff --git a/internal/router/statemachine.go b/internal/router/statemachine.go index 4f02b47..62d7f7c 100644 --- a/internal/router/statemachine.go +++ b/internal/router/statemachine.go @@ -101,6 +101,7 @@ func deviceChanges(_ string, current, previous data.Device, et data.EventType) e if current.Endpoint.String() != previous.Endpoint.String() { + log.Printf("challenging %s:%s device, as endpoint changed: %s -> %s", current.Username, current.Address, current.Endpoint.String(), previous.Endpoint.String()) // Will take at most 4 seconds err := Verifier.Challenge(current.Address) if err != nil { @@ -109,6 +110,8 @@ func deviceChanges(_ string, current, previous data.Device, et data.EventType) e if err != nil { return fmt.Errorf("cannot deauthenticate device %s: %s", current.Address, err) } + } else { + log.Printf("%s:%s device succeeded challenge", current.Username, current.Address) } }