Skip to content

Commit 671b2fc

Browse files
chore: Upgrade haproxy-spoe-go to v1.0.7 and remove manual workgroup handling (#119)
Upgrade haproxy-spoe-go to v1.0.7 and remove manual workgroup handling - Updated github.com/negasus/haproxy-spoe-go from v1.0.5 to v1.0.7 - Removed HAWaitGroup from Spoa struct as library now handles workgroup internally - Removed manual Add/Done calls from handlerWrapper - Simplified Shutdown method - library now waits for handlers when listeners are closed - Removed unused sync import
1 parent c8d659f commit 671b2fc

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/crowdsecurity/go-cs-bouncer v0.0.19
88
github.com/crowdsecurity/go-cs-lib v0.0.23
99
github.com/google/uuid v1.6.0
10-
github.com/negasus/haproxy-spoe-go v1.0.5
10+
github.com/negasus/haproxy-spoe-go v1.0.7
1111
github.com/oschwald/geoip2-golang v1.9.0
1212
github.com/prometheus/client_golang v1.23.2
1313
github.com/prometheus/client_model v0.6.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
7777
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
7878
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
7979
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
80-
github.com/negasus/haproxy-spoe-go v1.0.5 h1:iMUOg/WTdwh4qOD5VUWqXElIG6YefqdOZbTzbVXN8ZU=
81-
github.com/negasus/haproxy-spoe-go v1.0.5/go.mod h1:ZrBizxtx2EeLN37Jkg9w9g32a1AFCJizA8vg46PaAp4=
80+
github.com/negasus/haproxy-spoe-go v1.0.7 h1:OhRY0zapeHudrRqoblI9DjIolJjWI0s/TO6kT/va0ao=
81+
github.com/negasus/haproxy-spoe-go v1.0.7/go.mod h1:ZrBizxtx2EeLN37Jkg9w9g32a1AFCJizA8vg46PaAp4=
8282
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
8383
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
8484
github.com/oschwald/geoip2-golang v1.9.0 h1:uvD3O6fXAXs+usU+UGExshpdP13GAqp4GBrzN7IgKZc=

pkg/spoa/root.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/http"
99
"net/netip"
1010
"strings"
11-
"sync"
1211
"syscall"
1312

1413
"github.com/crowdsecurity/crowdsec-spoa/internal/geo"
@@ -34,7 +33,6 @@ type Spoa struct {
3433
ListenAddr net.Listener
3534
ListenSocket net.Listener
3635
Server *agent.Agent
37-
HAWaitGroup *sync.WaitGroup
3836
logger *log.Entry
3937
// Direct access to shared data (no IPC needed)
4038
dataset *dataset.DataSet
@@ -73,7 +71,6 @@ func New(config *SpoaConfig) (*Spoa, error) {
7371
// No worker-specific log level; inherits from parent logger
7472

7573
s := &Spoa{
76-
HAWaitGroup: &sync.WaitGroup{},
7774
logger: workerLogger,
7875
dataset: config.Dataset,
7976
hostManager: config.HostManager,
@@ -162,29 +159,19 @@ func (s *Spoa) Serve(ctx context.Context) error {
162159
func (s *Spoa) Shutdown(ctx context.Context) error {
163160
s.logger.Info("Shutting down")
164161

165-
doneChan := make(chan struct{})
166-
167-
// Close TCP listener
162+
// Close TCP listener - the library now handles waiting for handlers internally
168163
if s.ListenAddr != nil {
169164
s.ListenAddr.Close()
170165
}
171166

172-
// Initially we didn't close the unix socket as we wanted to persist permissions
167+
// Close Unix socket - the library now handles waiting for handlers internally
173168
if s.ListenSocket != nil {
174169
s.ListenSocket.Close()
175170
}
176171

177-
go func() {
178-
s.HAWaitGroup.Wait()
179-
close(doneChan)
180-
}()
181-
182-
select {
183-
case <-ctx.Done():
184-
return ctx.Err()
185-
case <-doneChan:
186-
return nil
187-
}
172+
// The library's workgroup now handles waiting for all frame handlers to complete
173+
// when the listeners are closed, so we don't need to wait here
174+
return nil
188175
}
189176

190177
// HTTPRequestData holds parsed HTTP request data for reuse across handlers
@@ -708,9 +695,7 @@ func (s *Spoa) handleIPRequest(req *request.Request, mes *message.Message) {
708695

709696
func handlerWrapper(s *Spoa) func(req *request.Request) {
710697
return func(req *request.Request) {
711-
s.HAWaitGroup.Add(1)
712-
defer s.HAWaitGroup.Done()
713-
698+
// The library now handles workgroup tracking internally, no need for manual Add/Done
714699
for _, messageName := range messageNames {
715700
mes, err := req.Messages.GetByName(messageName)
716701
if err != nil {

0 commit comments

Comments
 (0)