Skip to content

Commit b15b427

Browse files
Copybara Servicecopybara-github
authored andcommitted
Fix data race in fleetspeak messageServer.ServeHTTP
PiperOrigin-RevId: 936594207
1 parent 02d89d9 commit b15b427

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

fleetspeak/src/server/https/message_server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ func (s messageServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
9595
Start: db.Now(),
9696
Status: http.StatusTeapot, // Should never actually be returned
9797
}
98+
var processingStarted bool
9899
defer func() {
99100
fin()
100101
if pi.Status == http.StatusTeapot {
101102
log.Errorf("Forgot to set status.")
102103
}
103104
pi.End = db.Now()
104105
s.fs().StatsCollector().ClientPoll(pi)
106+
if processingStarted {
107+
s.stopProcessing()
108+
}
105109
}()
106110

107111
if !s.startProcessing() {
@@ -110,7 +114,7 @@ func (s messageServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
110114
http.Error(res, "Server not ready.", pi.Status)
111115
return
112116
}
113-
defer s.stopProcessing()
117+
processingStarted = true
114118

115119
if req.Method != http.MethodPost {
116120
pi.Status = http.StatusBadRequest

0 commit comments

Comments
 (0)