dogmatiq / linger Goto Github PK
View Code? Open in Web Editor NEWTimeout and retry utilities for Go.
License: MIT License
Timeout and retry utilities for Go.
License: MIT License
See dogmatiq/dogma#112 and dogmatiq/dogma@b3c4407 for an example.
We've noticed when configuring Dogma services using WithNetworking(...)
, for example:
// Set up the Dogma engine.
provide(func(
app dogma.Application,
p persistence.Provider,
l logging.Logger,
) *verity.Engine {
targetPort := util.GetEnv("DOGMAAPI_PORT", "50555")
namespace := util.GetEnv("NAMESPACE", "default")
return verity.New(
app,
verity.WithPersistence(p),
verity.WithLogger(l),
verity.WithNetworking(
verity.WithListenAddress(fmt.Sprintf(":%s", targetPort)),
verity.WithDiscoverer(discoverkit.StaticTargetDiscoverer{
discoverkit.Target{
Name: fmt.Sprintf("stack-casinogroup.%s.svc.cluster.local:50555", namespace),
DialOptions: []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())},
},
}),
),
)
})
that we periodically hit the following stacktrace:
panic: invalid argument to Int63n
goroutine 90 [running]:
math/rand.(*Rand).Int63n(0x1400021fd88?, 0x3ff0000000000000?)
/usr/local/go/src/math/rand/rand.go:110 +0xec
math/rand.Int63n(...)
/usr/local/go/src/math/rand/rand.go:327
github.com/dogmatiq/linger.Rand(0x2?, 0x4197d78400000000?)
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/linger@v0.2.1/jitter.go:42 +0x40
github.com/dogmatiq/linger.FullJitter(0x10094d94c?)
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/linger@v0.2.1/jitter.go:14 +0x24
github.com/dogmatiq/linger/backoff.WithTransforms.func1({0x100bf8f80?, 0x1400007e540?}, 0x0?)
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/linger@v0.2.1/backoff/strategy.go:95 +0x58
github.com/dogmatiq/linger/backoff.(*Counter).Fail(0x0?, {0x100bf8f80?, 0x1400007e540?})
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/linger@v0.2.1/backoff/counter.go:40 +0x90
github.com/dogmatiq/linger/backoff.(*Counter).Sleep(0x140001ae840?, {0x100c026b8, 0x140003c2b00}, {0x100bf8f80?, 0x1400007e540?})
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/linger@v0.2.1/backoff/counter.go:53 +0x34
github.com/dogmatiq/discoverkit.(*ApplicationDiscoverer).DiscoverApplications(0x1400035c900, {0x100c026b8, 0x140003c2b00}, {{0x140001ae840, 0x2f}, {0x140001c49a0, 0x2, 0x2}}, 0x0?)
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/discoverkit@v0.1.2/application.go:116 +0x114
github.com/dogmatiq/verity.(*Engine).targetDiscovered(0x14000376b40, {0x100c026b8, 0x140003c2b00}, {{0x140001ae840, 0x2f}, {0x140001c49a0, 0x2, 0x2}}, 0x0?)
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/verity@v0.1.1/network.go:156 +0x1a0
created by github.com/dogmatiq/verity.(*Engine).runDiscoverer.func2
/Users/sameaste/go/pkg/mod/github.com/dogmatiq/verity@v0.1.1/network.go:131 +0x128
Error: exit status 2
I've been able to reproduce the issue in isolation using the following code:
package main
import (
"github.com/dogmatiq/linger"
"math"
)
func main() {
_ = linger.FullJitter(math.MaxInt64)
}
Because the current implementation uses rand.Int63n()
, it adds 1 to the upper bound to try to make the range inclusive, but this causes an overflow when the upper bound is MaxDuration
.
See the template repo CI configuration.
panic: invalid argument to Int63n
goroutine 26 [running]:
math/rand.(*Rand).Int63n(0xc00009c420, 0x8000000000000001, 0x3ff0000000000000)
/usr/local/Cellar/go/1.13.6/libexec/src/math/rand/rand.go:111 +0x11d
math/rand.Int63n(...)
/usr/local/Cellar/go/1.13.6/libexec/src/math/rand/rand.go:319
github.com/dogmatiq/linger.Rand(0x0, 0x8000000000000000, 0x3f847ae147ae147b)
/Users/james/go/pkg/mod/github.com/dogmatiq/[email protected]/jitter.go:42 +0x55
github.com/dogmatiq/linger.FullJitter(0x8000000000000000, 0x0)
/Users/james/go/pkg/mod/github.com/dogmatiq/[email protected]/jitter.go:14 +0x34
github.com/dogmatiq/linger/backoff.WithTransforms.func1(0x0, 0x0, 0x28, 0x4505013)
/Users/james/go/pkg/mod/github.com/dogmatiq/[email protected]/backoff/strategy.go:71 +0x84
github.com/dogmatiq/linger/backoff.(*Counter).Fail(0xc0001f6798, 0x0, 0x0, 0x0)
/Users/james/go/pkg/mod/github.com/dogmatiq/[email protected]/backoff/counter.go:40 +0x54
github.com/dogmatiq/linger/backoff.(*Counter).Sleep(0xc0001f6798, 0x485ec80, 0xc0001f67c0, 0x0, 0x0, 0x24, 0x0)
/Users/james/go/pkg/mod/github.com/dogmatiq/[email protected]/backoff/counter.go:53 +0x43
github.com/dogmatiq/infix/persistence/provider/sql.(*cursor).Next(0xc0001f6780, 0x485ec80, 0xc0001f67c0, 0x0, 0x0, 0x0)
/Users/james/grit/github.com/dogmatiq/infix/persistence/provider/sql/stream.go:214 +0x238
github.com/dogmatiq/infix/app/projection.(*Projector).consumeNext(0xc0001d0000, 0x485ec80, 0xc000134140, 0x4857480, 0xc0001f6780, 0x0, 0x0)
/Users/james/grit/github.com/dogmatiq/infix/app/projection/projector.go:181 +0x71
github.com/dogmatiq/infix/app/projection.(*Projector).consume(0xc0001d0000, 0x485ec80, 0xc000134140, 0x0, 0x0)
/Users/james/grit/github.com/dogmatiq/infix/app/projection/projector.go:138 +0x553
github.com/dogmatiq/infix/app/projection.(*Projector).Run(0xc0001d0000, 0x485ec80, 0xc000134140, 0xc000168088, 0xc00007a838)
/Users/james/grit/github.com/dogmatiq/infix/app/projection/projector.go:70 +0x137
github.com/dogmatiq/infix.(*Engine).streamEvents.func1(0xc00004e768, 0xc00004e798)
/Users/james/grit/github.com/dogmatiq/infix/app.go:57 +0x3f
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc000142270, 0xc0001324e0)
/Users/james/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
/Users/james/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x66
These are functions to return a duration/time capped within a certain range.
Limit(d, min, max time.Duration) time.Duration
LimitT(t, min, max time.Time) time.Time
As per the changes to the CI configuration template in dogmatiq/template-go@eb5bb57.
It would be great to be able to coalesce multiple strategies into one. This would enable users to create strategies with default behavior, without having to implement a custom strategy themselves. This could be done with a func like CoalesceStrategy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.