Skip to content

Commit 154d214

Browse files
Handle context cancellation in consumeRowCopyComplete to prevent deadlocks (#1677)
Co-authored-by: meiji163 <meiji163@github.com>
1 parent fe459a9 commit 154d214

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

go/logic/migrator.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,16 @@ func (mgtr *Migrator) retryOperationWithExponentialBackoff(operation func() erro
234234
// consumeRowCopyComplete blocks on the rowCopyComplete channel once, and then
235235
// consumes and drops any further incoming events that may be left hanging.
236236
func (mgtr *Migrator) consumeRowCopyComplete() {
237-
if err := <-mgtr.rowCopyComplete; err != nil {
238-
// Abort synchronously to ensure checkAbort() sees the error immediately
239-
mgtr.abort(err)
240-
// Don't mark row copy as complete if there was an error
237+
select {
238+
case err := <-mgtr.rowCopyComplete:
239+
if err != nil {
240+
// Abort synchronously to ensure checkAbort() sees the error immediately
241+
mgtr.abort(err)
242+
// Don't mark row copy as complete if there was an error
243+
return
244+
}
245+
case <-mgtr.migrationContext.GetContext().Done():
246+
// Abort cancelled the context
241247
return
242248
}
243249
atomic.StoreInt64(&mgtr.rowCopyCompleteFlag, 1)

0 commit comments

Comments
 (0)