Skip to content

Commit

Permalink
worker(dm): fix deadlock (#5427)
Browse files Browse the repository at this point in the history
close #5089
  • Loading branch information
lance6716 authored May 16, 2022
1 parent 76e95e2 commit 4a99270
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dm/dm/worker/source_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (w *SourceWorker) Start() {
continue
}
}
if err2 := w.updateSourceStatus(w.ctx); err2 != nil {
if err2 := w.updateSourceStatus(w.ctx, true); err2 != nil {
if terror.ErrNoMasterStatus.Equal(err2) {
w.l.Warn("This source's bin_log is OFF, so it only supports full_mode.", zap.String("sourceID", w.cfg.SourceID), zap.Error(err2))
} else {
Expand Down Expand Up @@ -248,11 +248,16 @@ func (w *SourceWorker) Stop(graceful bool) {
}

// updateSourceStatus updates w.sourceStatus.
func (w *SourceWorker) updateSourceStatus(ctx context.Context) error {
func (w *SourceWorker) updateSourceStatus(ctx context.Context, needLock bool) error {
var cfg *config.SourceConfig
if needLock {
w.RLock()
cfg = w.cfg
w.RUnlock()
} else {
cfg = w.cfg
}
w.sourceDBMu.Lock()
w.RLock()
cfg := w.cfg
w.RUnlock()
if w.sourceDB == nil {
var err error
w.sourceDB, err = conn.DefaultDBProvider.Apply(&cfg.DecryptPassword().From)
Expand Down Expand Up @@ -669,7 +674,7 @@ func (w *SourceWorker) QueryStatus(ctx context.Context, name string) ([]*pb.SubT
relayStatus *pb.RelayStatus
)

if err := w.updateSourceStatus(ctx); err != nil {
if err := w.updateSourceStatus(ctx, false); err != nil {
if terror.ErrNoMasterStatus.Equal(err) {
w.l.Warn("This source's bin_log is OFF, so it only supports full_mode.", zap.String("sourceID", w.cfg.SourceID), zap.Error(err))
} else {
Expand Down

0 comments on commit 4a99270

Please sign in to comment.