Skip to content

Commit

Permalink
add mutex for presence detection (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett authored Dec 6, 2024
1 parent 5783a6c commit 9818435
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ee/localserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"runtime"
"strings"
"sync"
"time"

"github.com/kolide/krypto"
Expand Down Expand Up @@ -59,7 +60,8 @@ type localServer struct {
serverKey *rsa.PublicKey
serverEcKey *ecdsa.PublicKey

presenceDetector presenceDetector
presenceDetector presenceDetector
presenceDetectionMutex sync.Mutex
}

const (
Expand Down Expand Up @@ -416,6 +418,9 @@ func (ls *localServer) rateLimitHandler(next http.Handler) http.Handler {

func (ls *localServer) presenceDetectionHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// ensure we only prompt for 1 presence detection at a time
ls.presenceDetectionMutex.Lock()
defer ls.presenceDetectionMutex.Unlock()

// can test this by adding an unauthed endpoint to the mux and running, for example:
// curl -i -H "X-Kolide-Presence-Detection-Interval: 10s" -H "X-Kolide-Presence-Detection-Reason: my reason" localhost:12519/id
Expand Down

0 comments on commit 9818435

Please sign in to comment.