Skip to content

Commit 2a76920

Browse files
authored
pkg/settings: use sync.OnceFunc to prevent double close (#1765)
1 parent 5014d5e commit 2a76920

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/settings/map.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"strconv"
8+
"sync"
89

910
"github.com/smartcontractkit/chainlink-common/pkg/contexts"
1011
)
@@ -102,5 +103,5 @@ func (s *SettingMap[T]) Subscribe(ctx context.Context, registry Registry) (<-cha
102103

103104
// no-op
104105
ch := make(chan Update[T])
105-
return ch, func() { close(ch) }
106+
return ch, sync.OnceFunc(func() { close(ch) })
106107
}

pkg/settings/settings.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"reflect"
1010
"strconv"
11+
"sync"
1112
"time"
1213

1314
"golang.org/x/time/rate"
@@ -236,10 +237,10 @@ func (s *Setting[T]) Subscribe(ctx context.Context, r Registry) (<-chan Update[T
236237
}
237238
}
238239
}()
239-
return values, func() {
240+
return values, sync.OnceFunc(func() {
240241
stop()
241242
close(stopped)
242-
}
243+
})
243244
}
244245

245246
// InitConfig accepts a pointer to a config struct and iterates over all the fields, initializing any Setting fields

0 commit comments

Comments
 (0)