8000 Don't error on cancelled startup to make it not necessary to export `ErrShutdown` by brandur · Pull Request #841 · riverqueue/river · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't error on cancelled startup to make it not necessary to export ErrShutdown #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Client no longer returns an error if stopped before startup could complete (previously, it returned the unexported `ErrShutdown`). [PR #841](https://github.com/riverqueue/river/pull/841).

## [0.20.2] - 2025-04-08

### Added
Expand Down
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ func (c *Client[TTx]) Start(ctx context.Context) error {
}(); err != nil {
defer stopped()
if errors.Is(context.Cause(fetchCtx), startstop.ErrStop) {
return rivercommon.ErrShutdown
return nil
}
return err
}
Expand Down Expand Up @@ -928,7 +928,7 @@ func (c *Client[TTx]) Start(ctx context.Context) error {
startstop.StopAllParallel(producersAsServices()...)
c.baseService.Logger.DebugContext(ctx, c.baseService.Name+": All producers stopped")

c.workCancel(rivercommon.ErrShutdown)
c.workCancel(rivercommon.ErrStop)

// Stop all mainline services where stop order isn't important.
startstop.StopAllParallel(append(
Expand Down Expand Up @@ -985,7 +985,7 @@ func (c *Client[TTx]) Stop(ctx context.Context) error {
// instead.
func (c *Client[TTx]) StopAndCancel(ctx context.Context) error {
c.baseService.Logger.InfoContext(ctx, c.baseService.Name+": Hard stop started; cancelling all work")
c.workCancel(rivercommon.ErrShutdown)
c.workCancel(rivercommon.ErrStop)

shouldStop, stopped, finalizeStop := c.baseStartStop.StopInit()
if !shouldStop {
Expand Down
8 changes: 2 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,7 @@ func Test_Client(t *testing.T) {
err := client.Queues().Add(fmt.Sprintf("new_queue_%d_%d_before", workerNum, j), QueueConfig{MaxWorkers: 1})
require.NoError(t, err)

err = client.Start(ctx)
if !errors.Is(err, rivercommon.ErrShutdown) {
require.NoError(t, err)
}
require.NoError(t, client.Start(ctx))

err = client.Queues().Add(fmt.Sprintf("new_queue_%d_%d_after", workerNum, j), QueueConfig{MaxWorkers: 1})
require.NoError(t, err)
Expand Down Expand Up @@ -1104,7 +1101,7 @@ func Test_Client(t *testing.T) {

clientWithStop := &clientWithSimpleStop[pgx.Tx]{Client: client}

startstoptest.StressErr(ctx, t, clientWithStop, rivercommon.ErrShutdown)
startstoptest.Stress(ctx, t, clientWithStop)
})
}

Expand Down Expand Up @@ -1405,7 +1402,6 @@ func Test_Client_StopAndCancel(t *testing.T) {
t.Logf("Job waiting for context cancellation")
defer t.Logf("Job finished")
<-ctx.Done()
require.ErrorIs(t, context.Cause(ctx), rivercommon.ErrShutdown)
t.Logf("Job context done, closing chan and returning")
close(jobDoneChan)
return nil
Expand Down
7 changes: 3 additions & 4 deletions internal/rivercommon/river_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const (

type ContextKeyClient struct{}

// ErrShutdown is a special error injected by the client into its fetch and work
// ErrStop is a special error injected by the client into its fetch and work
// CancelCauseFuncs when it's stopping. It may be used by components for such
// cases like avoiding logging an error during a normal shutdown procedure. This
// is internal for the time being, but we could also consider exposing it.
var ErrShutdown = errors.New("shutdown initiated")
// cases like avoiding logging an error during a normal shutdown procedure.
var ErrStop = errors.New("stop initiated")
Loading
0