Skip to content

Commit bd886af

Browse files
authored
POA-2904 Use sync.Once (#84)
Tested locally: ``` [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 6027135 commit bd886af

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

data_masks/redactor.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"regexp"
66
"strings"
7-
"sync/atomic"
7+
"sync"
88
"time"
99

1010
pb "github.com/akitasoftware/akita-ir/go/api_spec"
@@ -36,9 +36,8 @@ type Redactor struct {
3636
// userConfig should exit.
3737
exitChannel chan struct{}
3838

39-
// Whether this redactor is still running. False if and only if exitChannel is
40-
// closed.
41-
running *atomic.Bool
39+
// Ensures that exitChannel is closed at most once.
40+
closeExitChannelOnce *sync.Once
4241
}
4342

4443
// Creates a redactor for the given service ID. Uses the given learn client to
@@ -107,22 +106,19 @@ func NewRedactor(
107106
}
108107
}()
109108

110-
running := &atomic.Bool{}
111-
running.Store(true)
112-
113109
return &Redactor{
114110
SensitiveDataKeys: sets.NewSet(config.SensitiveKeys...),
115111
SensitiveDataValuePatterns: sensitiveDataRegex,
116112
userConfig: activeUserConfig,
117113
exitChannel: exitChannel,
118-
running: running,
114+
closeExitChannelOnce: &sync.Once{},
119115
}, nil
120116
}
121117

122118
func (o *Redactor) StopPeriodicUpdates() {
123-
if o.running.Swap(false) {
119+
o.closeExitChannelOnce.Do(func() {
124120
close(o.exitChannel)
125-
}
121+
})
126122
}
127123

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

0 commit comments

Comments
 (0)