Skip to content

Commit abcd5c6

Browse files
authored
Merge pull request #83 from hyp3rd/fix/260225
chore(deps): bump buf to v1.66.0 and golang.org/x/net to v0.51.0
2 parents a7788c8 + 7e103f9 commit abcd5c6

7 files changed

Lines changed: 36 additions & 18 deletions

File tree

.pre-commit-ci-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
types: [file, yaml]
2222
entry: yamllint --strict -f parsable
2323
- repo: https://github.com/streetsidesoftware/cspell-cli
24-
rev: v9.4.0
24+
rev: v9.7.0
2525
hooks:
2626
# Spell check changed files
2727
- id: cspell

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030
hooks:
3131
- id: hadolint-docker
3232
- repo: https://github.com/streetsidesoftware/cspell-cli
33-
rev: v9.4.0
33+
rev: v9.7.0
3434
hooks:
3535
# Spell check changed files
3636
- id: cspell

.project-settings.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GOLANGCI_LINT_VERSION=v2.10.1
2-
BUF_VERSION=v1.65.0
2+
BUF_VERSION=v1.66.0
33
GO_VERSION=1.26.0
44
GCI_PREFIX=github.com/hyp3rd/hypercache
5-
PROTO_ENABLED=true
5+
PROTO_ENABLED=false

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include .project-settings.env
22

33
GOLANGCI_LINT_VERSION ?= v2.10.1
4-
BUF_VERSION ?= v1.65.0
4+
BUF_VERSION ?= v1.66.0
55
GO_VERSION ?= 1.26.0
66
GCI_PREFIX ?= github.com/hyp3rd/hypercache
77
PROTO_ENABLED ?= true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
github.com/valyala/fasthttp v1.69.0 // indirect
3838
go.uber.org/atomic v1.11.0 // indirect
3939
golang.org/x/crypto v0.48.0 // indirect
40-
golang.org/x/net v0.50.0 // indirect
40+
golang.org/x/net v0.51.0 // indirect
4141
golang.org/x/sys v0.41.0 // indirect
4242
golang.org/x/text v0.34.0 // indirect
4343
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
9494
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
9595
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
9696
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
97-
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
98-
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
97+
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
98+
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
9999
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
100100
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
101101
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=

hypercache.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,15 @@ func (hyperCache *HyperCache[T]) startBackgroundJobs(ctx context.Context) {
365365
jobsCtx, cancel := context.WithCancel(ctx)
366366

367367
hyperCache.bgCancel = cancel
368+
// Ensure shutdown signaling always drives context cancellation, even when
369+
// stop consumers race to read the stop channel.
370+
go func(stop <-chan bool, done <-chan struct{}, cancel context.CancelFunc) {
371+
select {
372+
case <-stop:
373+
cancel()
374+
case <-done:
375+
}
376+
}(hyperCache.stop, jobsCtx.Done(), cancel)
368377

369378
hyperCache.startExpirationRoutine(jobsCtx)
370379
hyperCache.startEvictionRoutine(jobsCtx)
@@ -415,6 +424,13 @@ func (hyperCache *HyperCache[T]) handleExpirationSelect(ctx context.Context, tic
415424
case <-hyperCache.evictCh:
416425
// manual eviction trigger
417426
hyperCache.evictionLoop(ctx)
427+
case <-ctx.Done():
428+
if tick != nil {
429+
tick.Stop()
430+
}
431+
432+
return true
433+
418434
case <-hyperCache.stop:
419435
if tick != nil {
420436
tick.Stop()
@@ -439,6 +455,11 @@ func (hyperCache *HyperCache[T]) startEvictionRoutine(ctx context.Context) {
439455
select {
440456
case <-tick.C:
441457
hyperCache.evictionLoop(ctx)
458+
case <-ctx.Done():
459+
tick.Stop()
460+
461+
return
462+
442463
case <-hyperCache.stop:
443464
tick.Stop()
444465

@@ -967,17 +988,16 @@ const (
967988

968989
// Stop function stops the expiration and eviction loops and closes the stop channel.
969990
func (hyperCache *HyperCache[T]) Stop(ctx context.Context) error {
970-
// Stop the expiration and eviction loops
971-
wg := sync.WaitGroup{}
972-
973-
wg.Go(func() {
974-
hyperCache.stop <- true
975-
})
976-
977-
wg.Wait()
991+
// Best-effort stop signal for listeners that still rely on stop channel.
992+
select {
993+
case hyperCache.stop <- true:
994+
default:
995+
}
978996

979997
if hyperCache.bgCancel != nil {
980998
hyperCache.bgCancel()
999+
1000+
hyperCache.bgCancel = nil
9811001
}
9821002

9831003
hyperCache.once = sync.Once{}
@@ -992,8 +1012,6 @@ func (hyperCache *HyperCache[T]) Stop(ctx context.Context) error {
9921012
// Handle error
9931013
return err
9941014
}
995-
996-
cancel()
9971015
}
9981016

9991017
return nil

0 commit comments

Comments
 (0)