Skip to content

Commit 9a3f94d

Browse files
authored
fix #3532 "reload causes crashing process" (#3534)
1 parent 2641a6c commit 9a3f94d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

pkg/apiclient/client.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ type service struct {
7272
}
7373

7474
func InitLAPIClient(ctx context.Context, apiUrl string, papiUrl string, login string, password string, scenarios []string) error {
75-
if lapiClient != nil {
76-
return errors.New("client already initialized")
77-
}
78-
7975
apiURL, err := url.Parse(apiUrl)
8076
if err != nil {
8177
return fmt.Errorf("parsing api url ('%s'): %w", apiURL, err)

test/bats/01_crowdsec.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,29 @@ teardown() {
124124
assert_stderr --partial "api server init: unable to run local API: controller init: CS_LAPI_SECRET not strong enough"
125125
}
126126

127+
@test "crowdsec - reload" {
128+
# we test that reload works as intended with the agent enabled
129+
130+
logfile="$(config_get '.common.log_dir')/crowdsec.log"
131+
132+
rune -0 truncate -s0 "$logfile"
133+
134+
rune -0 ./instance-crowdsec start-pid
135+
PID="$output"
136+
137+
sleep .5
138+
rune -0 kill -HUP "$PID"
139+
140+
sleep 5
141+
rune -0 ps "$PID"
142+
143+
assert_file_contains "$logfile" "Reload is finished"
144+
}
145+
127146
@test "crowdsec - reload (change of logfile, disabled agent)" {
147+
# we test that reload works as intended with the agent disabled
148+
# and that we can change the log configuration
149+
128150
logdir1=$(TMPDIR="$BATS_TEST_TMPDIR" mktemp -u)
129151
log_old="${logdir1}/crowdsec.log"
130152
config_set ".common.log_dir=\"${logdir1}\""

0 commit comments

Comments
 (0)