AppSec: SIGHUP reload deadlocks in shutdown — handlers block on InChan after runners exit, server.Shutdown waits forever
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start at pkg/acquisition/modules/appsec/config.go appsecHandler around line 468, where the unconditional send w.InChan <- parsedRequest blocks, then read pkg/acquisition/modules/appsec/run.go listenAndServe (the unbounded server.Shutdown) and cmd/crowdsec/serve.go ShutdownCrowdsecRoutines/shutdownCrowdsec to see the shutdown order. The issue lists three candidate fixes; pick one and check existing tests under pkg/acquisition/modules/appsec/ for shutdown/HTTP coverage to extend. Done means a SIGHUP with at least one in-flight AppSec request completes the reload instead of hanging, verified by a test or a reproduced reload run.
Written by the indexing model from the issue text.
Description
What happened?
A SIGHUP reload (sent by the packaged crowdsec-hubupdate after cscli hub upgrade found updates) never completed. The agent stopped all acquisition — file datasources and AppSec — and never started again. The process stayed alive, systemd kept reporting active (running), and nothing restarted it. WAF and log-based detection were both down for 8 hours until a manual systemctl restart (which itself had to fall back to SIGKILL after TimeoutStopSec).
The last lines in crowdsec.log, after which nothing is logged at all:
level=warning msg="SIGHUP received, reloading"
level=info msg="File datasource stopping" ...
level=info msg="Appsec Runner is dying" ...
There are no bind errors and no Error shutting down Appsec server — the reload never reaches the point of starting the new acquisition.
Goroutine dump of the hung process
Taken from /debug/pprof/goroutine?debug=1 before restarting. Relevant stacks (line numbers match commit 909b5157, the source of the 1.8.1 Debian package):
9 @ ...
# appsec.(*Source).appsecHandler+0x6f6 pkg/acquisition/modules/appsec/config.go:468
# net/http.HandlerFunc.ServeHTTP net/http/server.go:2286
# net/http.(*conn).serve net/http/server.go:2073
1 @ ...
# appsec.(*Source).listenAndServe+0x430 pkg/acquisition/modules/appsec/run.go:104
# appsec.(*Source).StreamingAcquisition.func1 pkg/acquisition/modules/appsec/run.go:153
1 @ ...
# main.ShutdownCrowdsecRoutines+0xc8 cmd/crowdsec/serve.go:113
# main.serveCrowdsec.func1 cmd/crowdsec/crowdsec.go:243
1 @ ...
# main.shutdownCrowdsec+0x53 cmd/crowdsec/serve.go:180
# main.shutdown cmd/crowdsec/serve.go:191
# main.HandleSignals.func1 cmd/crowdsec/serve.go:266
No AppSec runner goroutines are left.
Analysis
The shutdown order lets in-flight AppSec requests block forever:
acquisTomb.Kill(nil)— every goroutine of the AppSec source seesDying()at the same time.- The runners return immediately (
appsec_runner.go:564), so nothing readsinChanany more. - Requests that were already accepted by the HTTP server block in
appsecHandleron the unconditional sendw.InChan <- parsedRequest(config.go:468). There is noselectwith a cancellation case, so they can never return. listenAndServecallsw.server.Shutdown(ctx)(run.go:104).Shutdownwaits for active connections to finish, andctxhas no deadline, so it waits forever.acquisTomb.Wait()(serve.go:113) andcrowdsecTomb.Wait()(serve.go:180) never return; the reload never proceeds.
It only takes one request to be in flight at the moment the runners exit. On a bouncer with steady traffic (~7–8 inspected requests/s here) that is close to certain, so this is not a rare race in practice — it just only shows up on the nights when the hub actually upgrades something.
This is related to #4545 but is a different failure: there the shutdown completes and the listener leaks / fails to re-bind afterwards, here the shutdown itself never completes and there are no bind errors.
What did you expect to happen?
The reload completes, or — if AppSec cannot be stopped cleanly — the process fails loudly so a supervisor can restart it, instead of staying alive with every datasource stopped.
Possible fixes
Any one of these would break the cycle:
- In
appsecHandler, make the send toInChan(and the receive fromResponseChannelright after it) aselectthat also returns on shutdown, answering the bouncer with an error. - Call
server.Shutdownwith a bounded context and fall back toserver.Close()on timeout. - Shut the HTTP server down and let the runners drain
inChanbefore stopping the runners.
How can we reproduce it?
Enable AppSec, keep a steady stream of requests going through a bouncer, and send SIGHUP (or systemctl reload crowdsec). The hang needs at least one request to be inside appsecHandler when the runners exit.
Workaround
We replaced reload with restart both in a drop-in for crowdsec-hubupdate.service and in our configuration management handlers: a hung stop is then killed by systemd after TimeoutStopSec.
Crowdsec version
version: v1.8.1-debian-pragmatic-amd64-909b5157
Codename: alphaga
BuildDate: 2026-09-03_10:51:51
Installed from the crowdsec Debian package (1.8.1). AppSec enabled with the bot-challenge collections, OpenResty bouncer in front.
OS version
Ubuntu 22.04.5 LTS
Enabled collections and parsers
crowdsecurity/linux, sshd, nginx, base-http-scenarios, http-cve, http-dos, appsec-virtual-patching, appsec-generic-rules, appsec-bot-challenge-permissive, appsec-bot-challenge-good-bots, appsec-bot-challenge-exclude-paths, appsec-bot-challenge-scoring, plus a few local scenarios and parsers.
Acquisition config
File datasources on nginx and GitLab logs, plus:
source: appsec
listen_addr: <private address>:7422
appsec_configs:
- crowdsecurity/appsec-default
- crowdsecurity/appsec-bot-challenge-scoring
- crowdsecurity/appsec-bot-challenge-scoring-permissive
# ... bot-challenge exclusions ...
- Dominant language
- Go
- Stars
- 15.1k
- Forks
- 726
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 27
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from crowdsecurity/crowdsec
-
needs/kind needs/triage
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
crowdsecurity/crowdsec#4849 · 2 comments ·
Maintainers usually reply within 4 days
-
kind/bug needs/triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
crowdsecurity/crowdsec#4847 · 3 comments ·
Maintainers usually reply within 4 days
-
kind/bug needs/triage os/linux
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
crowdsecurity/crowdsec#4836 · 1 comment ·
Maintainers usually reply within 4 days
-
victorialogs datasource passes the trailing newline of a message to the parsers (traefik-logs 1.6 fails on every line)Possibly taken @IlayWolfson claimed this 6 days ago. Openkind/bug needs/triage os/linux version/1.8.2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
crowdsecurity/crowdsec#4820 · 1 comment ·
Maintainers usually reply within 4 days
-
[email protected]Openneeds/kind needs/triage
Difficulty 5/5 Over a week Newbie friendliness 10/100
crowdsecurity/crowdsec#4842 · 3 comments ·
Maintainers usually reply within 4 days
All issues in crowdsecurity/crowdsec
Similar issues
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainers usually reply within 1 day
-
Type: Enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
projectdiscovery/urlfinder#167 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
peterstace/simplefeatures#726 ·
-
area: import bug go good first issue priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
fukubie/StockLlama#69 ·
-
enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloverworks-hq/rumpty-cli#95 ·
Maintainers usually reply within 1 day