rproxy: one type for the goroutines sending reports (closes #433)
check / check (push) Waiting to run
check / check (push) Waiting to run
handler held a WaitGroup, a mutex and a stopped flag for the reports, and the rule that no report starts once waiting has begun was split between sendReport and Server.WaitForReports. reportGoroutines now holds all three, and its two methods are the only code that touches the lock and the flag. Model: opus-5-5
This commit is contained in:
1 parent
aaa28f541b
commit
69e62c3e37
2 files changed
+36
-19
No files matched your search
@@ -20,7 +20,6 @@ import (
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
||||
@@ -114,11 +113,7 @@ func New(params Params) *Server {
|
||||
// which SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS bounds. Any report after this call
|
||||
// is dropped: that of a WebSocket that closes while rproxy stops, for one.
|
||||
func (s *Server) WaitForReports() {
|
||||
s.h.reportsMu.Lock()
|
||||
s.h.reportsStopped = true
|
||||
s.h.reportsMu.Unlock()
|
||||
|
||||
s.h.reports.Wait()
|
||||
s.h.reports.stopAndWait()
|
||||
}
|
||||
|
||||
// handler is the proxy. It holds what every request shares; what belongs to
|
||||
@@ -138,11 +133,8 @@ type handler struct {
|
||||
// the time.
|
||||
breaker breaker
|
||||
breakerClock func() time.Time
|
||||
// reports waits for the reports being sent. reportsMu guards starting one
|
||||
// against reportsStopped, which is set once nothing is to wait for another.
|
||||
reports sync.WaitGroup
|
||||
reportsMu sync.Mutex
|
||||
reportsStopped bool
|
||||
// reports are the goroutines sending reports to waf.
|
||||
reports reportGoroutines
|
||||
}
|
||||
|
||||
// newTransport returns what carries requests to the app. It never goes through
|
||||
|
||||
Reference in new issue
Block a user