Fix race condition

This commit is contained in:
Ingo Oppermann 2023-05-02 10:59:57 +02:00
parent 7cca02f2b5
commit 3ee362a5fe
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E

View File

@ -79,6 +79,9 @@ func New(config Config) (Resources, error) {
r.maxCPU *= r.ncpu
r.maxMemory = uint64(float64(vmstat.Total) * config.MaxMemory / 100)
r.limitCPUCh = make(chan bool, 10)
r.limitMemoryCh = make(chan bool, 10)
r.logger = r.logger.WithFields(log.Fields{
"ncpu": r.ncpu,
"max_cpu": r.maxCPU,
@ -94,9 +97,6 @@ func New(config Config) (Resources, error) {
func (r *resources) Start() {
r.startOnce.Do(func() {
r.limitCPUCh = make(chan bool, 10)
r.limitMemoryCh = make(chan bool, 10)
ctx, cancel := context.WithCancel(context.Background())
r.cancelObserver = cancel