From b2934282657a7b71e988ed7a2df16add835f5031 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 28 Aug 2026 19:45:41 +0200 Subject: [PATCH] vendor: github.com/docker/go-events v0.1.0 full diff: https://github.com/docker/go-events/compare/e31b211e4f1c...v0.1.0 Signed-off-by: Sebastiaan van Stijn --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/docker/go-events/README.md | 4 +- .../github.com/docker/go-events/SECURITY.md | 36 ++++++++++++ .../github.com/docker/go-events/broadcast.go | 56 ++++++++----------- vendor/github.com/docker/go-events/channel.go | 14 +++-- vendor/github.com/docker/go-events/errors.go | 10 ++-- vendor/github.com/docker/go-events/event.go | 2 +- vendor/github.com/docker/go-events/filter.go | 21 ++++--- vendor/github.com/docker/go-events/queue.go | 1 + vendor/github.com/docker/go-events/retry.go | 55 ++++++++---------- vendor/modules.txt | 4 +- 12 files changed, 118 insertions(+), 91 deletions(-) create mode 100644 vendor/github.com/docker/go-events/SECURITY.md diff --git a/go.mod b/go.mod index 6563f674fe..281be14247 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/cloudflare/cfssl v1.6.4 github.com/container-storage-interface/spec v1.2.0 github.com/distribution/reference v0.5.0 - github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c + github.com/docker/go-events v0.1.0 github.com/docker/go-metrics v0.1.0 github.com/fernet/fernet-go v0.0.0-20211208181803-9f70042a33ee github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index e7317bc4b4..6d0b42e381 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= -github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8= -github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA= +github.com/docker/go-events v0.1.0 h1:J8VX4H7Ta8mmBhv/K/24x1kosKOrEEnYmGjcdFHTOW0= +github.com/docker/go-events v0.1.0/go.mod h1:jwVwMgySJX4PiukIIRrind1wPGU8QhPa8aTEPkreUj4= github.com/docker/go-metrics v0.1.0 h1:r76KPNpstz+IvQKSWpYegSkkyzex0V3A1ZGVx6bhGlY= github.com/docker/go-metrics v0.1.0/go.mod h1:PciI3sONtB051kXALN1JoIlpcu54E1FuPh+4DuqEzyw= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= diff --git a/vendor/github.com/docker/go-events/README.md b/vendor/github.com/docker/go-events/README.md index 0acafc279a..11e267f354 100644 --- a/vendor/github.com/docker/go-events/README.md +++ b/vendor/github.com/docker/go-events/README.md @@ -1,7 +1,7 @@ # Docker Events Package -[![GoDoc](https://godoc.org/github.com/docker/go-events?status.svg)](https://godoc.org/github.com/docker/go-events) -[![Circle CI](https://circleci.com/gh/docker/go-events.svg?style=shield)](https://circleci.com/gh/docker/go-events) +[![Go Reference](https://pkg.go.dev/badge/github.com/docker/go-events.svg)](https://pkg.go.dev/github.com/docker/go-events) +[![Build Status](https://github.com/docker/go-events/actions/workflows/ci.yml/badge.svg)](https://github.com/docker/go-events/actions/workflows/ci.yml) The Docker `events` package implements a composable event distribution package for Go. diff --git a/vendor/github.com/docker/go-events/SECURITY.md b/vendor/github.com/docker/go-events/SECURITY.md new file mode 100644 index 0000000000..610eef2c9e --- /dev/null +++ b/vendor/github.com/docker/go-events/SECURITY.md @@ -0,0 +1,36 @@ +# Security Policy + +The maintainers of the Docker Events package take security seriously. If you discover +a security issue, please bring it to their attention right away! + +## Reporting a Vulnerability + +Please **DO NOT** file a public issue, instead send your report privately +to [security@docker.com](mailto:security@docker.com). + +Reporter(s) can expect a response within 72 hours, acknowledging the issue was +received. + +## Review Process + +After receiving the report, an initial triage and technical analysis is +performed to confirm the report and determine its scope. We may request +additional information in this stage of the process. + +Once a reviewer has confirmed the relevance of the report, a draft security +advisory will be created on GitHub. The draft advisory will be used to discuss +the issue with maintainers, the reporter(s), and where applicable, other +affected parties under embargo. + +If the vulnerability is accepted, a timeline for developing a patch, public +disclosure, and patch release will be determined. If there is an embargo period +on public disclosure before the patch release, the reporter(s) are expected to +participate in the discussion of the timeline and abide by agreed upon dates +for public disclosure. + +## Accreditation + +Security reports are greatly appreciated and we will publicly thank you, +although we will keep your name confidential if you request it. We also like to +send gifts - if you're into swag, make sure to let us know. We do not currently +offer a paid security bounty program at this time. diff --git a/vendor/github.com/docker/go-events/broadcast.go b/vendor/github.com/docker/go-events/broadcast.go index 5120078dfb..ef8dd3f034 100644 --- a/vendor/github.com/docker/go-events/broadcast.go +++ b/vendor/github.com/docker/go-events/broadcast.go @@ -2,6 +2,7 @@ package events import ( "fmt" + "slices" "sync" "github.com/sirupsen/logrus" @@ -78,7 +79,8 @@ func (b *Broadcaster) configure(ch chan configureRequest, sink Sink) error { select { case ch <- configureRequest{ sink: sink, - response: response}: + response: response, + }: ch = nil case err := <-response: return err @@ -104,55 +106,46 @@ func (b *Broadcaster) Close() error { // Close is called, this goroutine will exit. func (b *Broadcaster) run() { defer close(b.closed) - remove := func(target Sink) { - for i, sink := range b.sinks { - if sink == target { - b.sinks = append(b.sinks[:i], b.sinks[i+1:]...) - break - } - } - } for { select { case event := <-b.events: - for _, sink := range b.sinks { + for i := 0; i < len(b.sinks); { + sink := b.sinks[i] if err := sink.Write(event); err != nil { if err == ErrSinkClosed { - // remove closed sinks - remove(sink) + b.sinks = slices.Delete(b.sinks, i, i+1) continue } - logrus.WithField("event", event).WithField("events.sink", sink).WithError(err). - Errorf("broadcaster: dropping event") + logrus.WithFields(logrus.Fields{ + "error": err, + "event": event, + "events.sink": sink, + }).Error("broadcaster: dropping event") } + i++ } case request := <-b.adds: // while we have to iterate for add/remove, common iteration for // send is faster against slice. - - var found bool - for _, sink := range b.sinks { - if request.sink == sink { - found = true - break - } - } - - if !found { + // b.sinks[request.sink] = struct{}{} + if !slices.Contains(b.sinks, request.sink) { b.sinks = append(b.sinks, request.sink) } - // b.sinks[request.sink] = struct{}{} request.response <- nil case request := <-b.removes: - remove(request.sink) + if i := slices.Index(b.sinks, request.sink); i >= 0 { + b.sinks = slices.Delete(b.sinks, i, i+1) + } request.response <- nil case <-b.shutdown: // close all the underlying sinks for _, sink := range b.sinks { if err := sink.Close(); err != nil && err != ErrSinkClosed { - logrus.WithField("events.sink", sink).WithError(err). - Errorf("broadcaster: closing sink failed") + logrus.WithFields(logrus.Fields{ + "error": err, + "events.sink": sink, + }).Error("broadcaster: closing sink failed") } } return @@ -163,8 +156,7 @@ func (b *Broadcaster) run() { func (b *Broadcaster) String() string { // Serialize copy of this broadcaster without the sync.Once, to avoid // a data race. - - b2 := map[string]interface{}{ + return fmt.Sprint(map[string]any{ "sinks": b.sinks, "events": b.events, "adds": b.adds, @@ -172,7 +164,5 @@ func (b *Broadcaster) String() string { "shutdown": b.shutdown, "closed": b.closed, - } - - return fmt.Sprint(b2) + }) } diff --git a/vendor/github.com/docker/go-events/channel.go b/vendor/github.com/docker/go-events/channel.go index 802cf51ffe..c58a2c3f57 100644 --- a/vendor/github.com/docker/go-events/channel.go +++ b/vendor/github.com/docker/go-events/channel.go @@ -34,10 +34,15 @@ func (ch *Channel) Done() chan struct{} { // the listener. func (ch *Channel) Write(event Event) error { select { - case ch.C <- event: - return nil case <-ch.closed: return ErrSinkClosed + default: + select { + case <-ch.closed: + return ErrSinkClosed + case ch.C <- event: + return nil + } } } @@ -53,9 +58,8 @@ func (ch *Channel) Close() error { func (ch *Channel) String() string { // Serialize a copy of the Channel that doesn't contain the sync.Once, // to avoid a data race. - ch2 := map[string]interface{}{ + return fmt.Sprint(map[string]any{ "C": ch.C, "closed": ch.closed, - } - return fmt.Sprint(ch2) + }) } diff --git a/vendor/github.com/docker/go-events/errors.go b/vendor/github.com/docker/go-events/errors.go index 56db7c2510..850fc03582 100644 --- a/vendor/github.com/docker/go-events/errors.go +++ b/vendor/github.com/docker/go-events/errors.go @@ -2,9 +2,7 @@ package events import "fmt" -var ( - // ErrSinkClosed is returned if a write is issued to a sink that has been - // closed. If encountered, the error should be considered terminal and - // retries will not be successful. - ErrSinkClosed = fmt.Errorf("events: sink closed") -) +// ErrSinkClosed is returned if a write is issued to a sink that has been +// closed. If encountered, the error should be considered terminal and +// retries will not be successful. +var ErrSinkClosed = fmt.Errorf("events: sink closed") diff --git a/vendor/github.com/docker/go-events/event.go b/vendor/github.com/docker/go-events/event.go index f0f1d9ea5f..8cd997a310 100644 --- a/vendor/github.com/docker/go-events/event.go +++ b/vendor/github.com/docker/go-events/event.go @@ -1,7 +1,7 @@ package events // Event marks items that can be sent as events. -type Event interface{} +type Event any // Sink accepts and sends events. type Sink interface { diff --git a/vendor/github.com/docker/go-events/filter.go b/vendor/github.com/docker/go-events/filter.go index e6c0eb69dd..5cf863029c 100644 --- a/vendor/github.com/docker/go-events/filter.go +++ b/vendor/github.com/docker/go-events/filter.go @@ -13,22 +13,27 @@ func (fn MatcherFunc) Match(event Event) bool { return fn(event) } -// Filter provides an event sink that sends only events that are accepted by a -// Matcher. No methods on filter are goroutine safe. -type Filter struct { +// Filter is the concrete implementation returned by [NewFilter]. +// +// Deprecated: Filter should not be constructed directly. Use [NewFilter] instead. +type Filter = filter + +type filter struct { dst Sink matcher Matcher closed bool } -// NewFilter returns a new filter that will send to events to dst that return -// true for Matcher. +// NewFilter returns a new event sink that forwards only events accepted by +// matcher to dst. +// +// The returned Sink's methods are not safe for concurrent use. func NewFilter(dst Sink, matcher Matcher) Sink { - return &Filter{dst: dst, matcher: matcher} + return &filter{dst: dst, matcher: matcher} } // Write an event to the filter. -func (f *Filter) Write(event Event) error { +func (f *filter) Write(event Event) error { if f.closed { return ErrSinkClosed } @@ -41,7 +46,7 @@ func (f *Filter) Write(event Event) error { } // Close the filter and allow no more events to pass through. -func (f *Filter) Close() error { +func (f *filter) Close() error { // TODO(stevvooe): Not all sinks should have Close. if f.closed { return nil diff --git a/vendor/github.com/docker/go-events/queue.go b/vendor/github.com/docker/go-events/queue.go index 4bb770afc2..b286405009 100644 --- a/vendor/github.com/docker/go-events/queue.go +++ b/vendor/github.com/docker/go-events/queue.go @@ -103,6 +103,7 @@ func (eq *Queue) next() Event { eq.cond.Wait() } + // Len is non-zero while holding eq.mu, so Front cannot be nil. front := eq.events.Front() block := front.Value.(Event) eq.events.Remove(front) diff --git a/vendor/github.com/docker/go-events/retry.go b/vendor/github.com/docker/go-events/retry.go index b7f0a54225..70fad9c47c 100644 --- a/vendor/github.com/docker/go-events/retry.go +++ b/vendor/github.com/docker/go-events/retry.go @@ -2,7 +2,7 @@ package events import ( "fmt" - "math/rand" + "math/rand/v2" "sync" "sync/atomic" "time" @@ -26,13 +26,11 @@ type RetryingSink struct { // off on failure. Parameters threshold and backoff adjust the behavior of the // circuit breaker. func NewRetryingSink(sink Sink, strategy RetryStrategy) *RetryingSink { - rs := &RetryingSink{ + return &RetryingSink{ sink: sink, strategy: strategy, closed: make(chan struct{}), } - - return rs } // Write attempts to flush the events to the downstream sink until it succeeds @@ -66,14 +64,12 @@ retry: return err } - logger := logger.WithError(err) // shadow!! - if rs.strategy.Failure(event, err) { - logger.Errorf("retryingsink: dropped event") + logger.WithError(err).Error("retryingsink: dropped event") return nil } - logger.Errorf("retryingsink: error writing event, retrying") + logger.WithError(err).Error("retryingsink: error writing event, retrying") goto retry } @@ -93,7 +89,7 @@ func (rs *RetryingSink) Close() error { func (rs *RetryingSink) String() string { // Serialize a copy of the RetryingSink without the sync.Once, to avoid // a data race. - rs2 := map[string]interface{}{ + rs2 := map[string]any{ "sink": rs.sink, "strategy": rs.strategy, "closed": rs.closed, @@ -151,7 +147,7 @@ func (b *Breaker) Proceed(event Event) time.Duration { return 0 } - return b.last.Add(b.backoff).Sub(time.Now()) + return time.Until(b.last.Add(b.backoff)) } // Success resets the breaker. @@ -173,15 +169,13 @@ func (b *Breaker) Failure(event Event, err error) bool { return false // never drop events. } -var ( - // DefaultExponentialBackoffConfig provides a default configuration for - // exponential backoff. - DefaultExponentialBackoffConfig = ExponentialBackoffConfig{ - Base: time.Second, - Factor: time.Second, - Max: 20 * time.Second, - } -) +// DefaultExponentialBackoffConfig provides a default configuration for +// exponential backoff. +var DefaultExponentialBackoffConfig = ExponentialBackoffConfig{ + Base: time.Second, + Factor: time.Second, + Max: 20 * time.Second, +} // ExponentialBackoffConfig configures backoff parameters. // @@ -203,7 +197,7 @@ type ExponentialBackoffConfig struct { // ExponentialBackoff implements random backoff with exponentially increasing // bounds as the number consecutive failures increase. type ExponentialBackoff struct { - failures uint64 // consecutive failure counter (needs to be 64-bit aligned) + failures atomic.Uint64 // consecutive failure counter (needs to be 64-bit aligned) config ExponentialBackoffConfig } @@ -217,17 +211,17 @@ func NewExponentialBackoff(config ExponentialBackoffConfig) *ExponentialBackoff // Proceed returns the next randomly bound exponential backoff time. func (b *ExponentialBackoff) Proceed(event Event) time.Duration { - return b.backoff(atomic.LoadUint64(&b.failures)) + return b.backoff(b.failures.Load()) } // Success resets the failures counter. func (b *ExponentialBackoff) Success(event Event) { - atomic.StoreUint64(&b.failures, 0) + b.failures.Store(0) } // Failure increments the failure counter. func (b *ExponentialBackoff) Failure(event Event, err error) bool { - atomic.AddUint64(&b.failures, 1) + b.failures.Add(1) return false } @@ -244,17 +238,16 @@ func (b *ExponentialBackoff) backoff(failures uint64) time.Duration { factor = DefaultExponentialBackoffConfig.Factor } - backoff := b.config.Base + factor*time.Duration(1<<(failures-1)) - - max := b.config.Max - if max <= 0 { - max = DefaultExponentialBackoffConfig.Max + maxBackoff := b.config.Max + if maxBackoff <= 0 { + maxBackoff = DefaultExponentialBackoffConfig.Max } - if backoff > max || backoff < 0 { - backoff = max + backoff := b.config.Base + factor*time.Duration(1<<(failures-1)) + if backoff > maxBackoff || backoff < 0 { + backoff = maxBackoff } // Choose a uniformly distributed value from [0, backoff). - return time.Duration(rand.Int63n(int64(backoff))) + return rand.N(backoff) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 58291515c9..67d07e57d2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -47,8 +47,8 @@ github.com/coreos/go-semver/semver # github.com/distribution/reference v0.5.0 ## explicit; go 1.20 github.com/distribution/reference -# github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c -## explicit +# github.com/docker/go-events v0.1.0 +## explicit; go 1.24 github.com/docker/go-events # github.com/docker/go-metrics v0.1.0 ## explicit; go 1.21