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

Commit

Permalink
syncer: do not try to handle jobs anymore if the context is done (#1295
Browse files Browse the repository at this point in the history
…) (#1304)

Signed-off-by: ti-srebot <[email protected]>

Co-authored-by: Xuecheng Zhang <[email protected]>
  • Loading branch information
ti-srebot and csuzhangxc authored Nov 26, 2020
1 parent 82e4c5f commit c90572f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit c90572f

Please sign in to comment.