-
Notifications
You must be signed in to change notification settings - Fork 188
worker: fix potential panic when restoring subtask from meta #305
Conversation
Codecov Report
@@ Coverage Diff @@
## master #305 +/- ##
===========================================
Coverage 60.1755% 60.1755%
===========================================
Files 134 134
Lines 14810 14810
===========================================
Hits 8912 8912
Misses 5059 5059
Partials 839 839 |
@amyangfei @WangXiangUSTC PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest LGTM
// release resources, NOTE: we need to refactor New/Init/Start/Close for components later. | ||
w2.cancel() | ||
w2.subTaskHolder.closeAllSubTasks() | ||
if w2.meta != nil { | ||
w2.meta.Close() | ||
} | ||
if w2.db != nil { | ||
w2.db.Close() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just use w2.Close(), and maybe need add some check in Close
(close something when it is not nil)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can.
But I also think we should refactor the pattern of components' new/init/start/close later.
like new
only creates fields but does not acquire (IO) resources and start no goroutines, then when new
failed, no operation needs to do and let GC to remove the objects is enough.
I think we need to do some refactoring when developing the HA version of DM.
what's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK,we can do this later
Co-Authored-By: WangXiangUSTC <wx347249478@gmail.com>
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cherry pick to release-1.0 in PR #311 |
What problem does this PR solve?
What is changed and how it works?
before this PR, we have the following order in worker.go:
InitConditionHub
registersWorker
instancesrestoreSubTask
restores subtasks from metaw.ctx, w.cancel = context.WithCancel(context.Background())
initsw.ctx
andw.cancel
but when restoring subtasks from meta,
w.ctx
may be used, thennil
pointer will be accessed and panicked.in this PR, we make sure have the following order:
w.ctx, w.cancel = context.WithCancel(context.Background())
initsw.ctx
andw.cancel
InitConditionHub
registersWorker
instancesrestoreSubTask
restores subtasks from metaCheck List
Tests
Related changes