Skip to content

Commit

Permalink
backupccl: put a goroutine under the stopper's control
Browse files Browse the repository at this point in the history
The backup processor was spawning a naked goroutine. We don't like that
very much - see cockroachdb#58164. This patch puts that goroutine under the
Stopper. One benefit is that the goroutine gets its own span, so it's
resilient to the parent span being Finish()ed from under it (which was a
bug until the prior commit).

Release note: None
  • Loading branch information
andreimatei committed Nov 10, 2021
1 parent 799b21b commit 8f3921d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/ccl/backupccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ go_library(
"//pkg/util/metric",
"//pkg/util/protoutil",
"//pkg/util/retry",
"//pkg/util/stop",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//pkg/util/tracing",
Expand Down
12 changes: 10 additions & 2 deletions pkg/ccl/backupccl/backup_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -158,11 +159,18 @@ func (bp *backupDataProcessor) Start(ctx context.Context) {
for range bp.progCh {
}
}
go func() {
if err := bp.flowCtx.Stopper().RunAsyncTaskEx(ctx, stop.TaskOpts{
TaskName: "backup-worker",
SpanOpt: stop.ChildSpan,
}, func(ctx context.Context) {
defer cancel()
defer close(bp.progCh)
bp.backupErr = runBackupProcessor(ctx, bp.flowCtx, &bp.spec, bp.progCh)
}()
}); err != nil {
bp.backupErr = err
cancel()
close(bp.progCh)
}
}

// Next is part of the RowSource interface.
Expand Down

0 comments on commit 8f3921d

Please sign in to comment.