Skip to content

Commit 662b4e3

Browse files
authored
POA-2904 Fix double close in redactor (#83)
Before: ``` [INFO] Running learn mode on interfaces lo, wlan0 [INFO] Send SIGINT (Ctrl-C) to stop... ^C[INFO] Received interrupt, stopping trace collection... panic: close of closed channel ``` After: ``` [INFO] Running learn mode on interfaces lo, wlan0 [INFO] Send SIGINT (Ctrl-C) to stop... ^C[INFO] Received interrupt, stopping trace collection... [INFO] Trace collection stopped [INFO] Did not capture any TCP packets matching the filter. This may mean your filter is incorrect, such as the wrong TCP port. [ERROR] No HTTP calls captured! 🛑 [ERROR] Error during initiaization: API trace is empty [INFO] This process will not exit, to avoid boot loops. Please correct the command line flags or environment and retry. ```
1 parent 61fd745 commit 662b4e3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

data_masks/redactor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"regexp"
66
"strings"
7+
"sync/atomic"
78
"time"
89

910
pb "github.com/akitasoftware/akita-ir/go/api_spec"
@@ -34,6 +35,10 @@ type Redactor struct {
3435
// When this channel is closed, it signals that the goroutine for updating
3536
// userConfig should exit.
3637
exitChannel chan struct{}
38+
39+
// Whether this redactor is still running. False if and only if exitChannel is
40+
// closed.
41+
running *atomic.Bool
3742
}
3843

3944
// Creates a redactor for the given service ID. Uses the given learn client to
@@ -102,16 +107,22 @@ func NewRedactor(
102107
}
103108
}()
104109

110+
running := &atomic.Bool{}
111+
running.Store(true)
112+
105113
return &Redactor{
106114
SensitiveDataKeys: sets.NewSet(config.SensitiveKeys...),
107115
SensitiveDataValuePatterns: sensitiveDataRegex,
108116
userConfig: activeUserConfig,
109117
exitChannel: exitChannel,
118+
running: running,
110119
}, nil
111120
}
112121

113122
func (o *Redactor) StopPeriodicUpdates() {
114-
close(o.exitChannel)
123+
if o.running.Swap(false) {
124+
close(o.exitChannel)
125+
}
115126
}
116127

117128
func (o *Redactor) RedactSensitiveData(m *pb.Method) {

0 commit comments

Comments
 (0)