Skip to content

Commit

Permalink
Fix double close of channel
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jun 10, 2024
1 parent 5ca5d44 commit 489a709
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/router/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ import (
type wsConnWrapper struct {
*websocket.Conn
wait chan interface{}
sync.Mutex
isClosed bool
}

func (ws *wsConnWrapper) Await() <-chan interface{} {
return ws.wait
}

func (ws *wsConnWrapper) Close() error {
ws.Lock()
defer ws.Unlock()

if ws.isClosed {
return nil
}

close(ws.wait)
return ws.Conn.Close()
}
Expand Down
3 changes: 3 additions & 0 deletions internal/router/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 489a709

Please sign in to comment.