Coder Social home page Coder Social logo

linger's Introduction

Linger

Timeout and retry utilities for Go.

Documentation Latest Version Build Status Code Coverage

linger's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar dogmatiq-automation[bot] avatar github-actions[bot] avatar jmalloc avatar pmallela avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

linger's Issues

panic: invalid argument to Int63n

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)
}

Rand() panics when passed MaxDuration.

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.

Issue with random number generation for jitter.

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

Allow coalescing multiple strategies into one Strategy

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.