Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

syncer: do not try to handle jobs anymore if the context is done (#1295) #1304

Merged
merged 1 commit into from
Nov 26, 2020
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
12 changes: 12 additions & 0 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,18 @@ func (s *Syncer) sync(tctx *tcontext.Context, queueBucket string, db *DBConn, jo
if len(jobs) == 0 {
return 0, nil
}

select {
case <-tctx.Ctx.Done():
// do not execute queries anymore, because they should be failed with a done context.
// and avoid some errors like:
// - `driver: bad connection` for `BEGIN`
// - `sql: connection is already closed` for `BEGIN`
tctx.L().Info("skip some remaining DML jobs in the job chan because the context is done", zap.Int("count", len(jobs)))
return 0, tctx.Ctx.Err() // return the error to trigger `fatalF`.
default:
}

queries := make([]string, 0, len(jobs))
args := make([][]interface{}, 0, len(jobs))
for _, j := range jobs {
Expand Down
3 changes: 3 additions & 0 deletions tests/incremental_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ function run() {
# meeting an error of context cancel.
# when below check pass, it means we filter out that error, or that error doesn't happen.
# we only focus on fails, to find any unfiltered context cancel error.
# and should not contain errors like:
# - `driver: bad connection`
# - `sql: connection is already closed`
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"pause-task test" \
"\"result\": true" 3
Expand Down