-
-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent infinite transition loops; more aggressive validate_state() #6318
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1262,6 +1262,7 @@ class SchedulerState: | |
"validate", | ||
"workers", | ||
"transition_counter", | ||
"transition_counter_max", | ||
"plugins", | ||
"UNKNOWN_TASK_DURATION", | ||
"MEMORY_RECENT_TO_OLD_TIME", | ||
|
@@ -1354,6 +1355,9 @@ def __init__( | |
/ 2.0 | ||
) | ||
self.transition_counter = 0 | ||
self.transition_counter_max = dask.config.get( | ||
"distributed.admin.transition-counter-max" | ||
) | ||
|
||
@property | ||
def memory(self) -> MemoryState: | ||
|
@@ -1430,16 +1434,24 @@ def _transition(self, key, finish: str, stimulus_id: str, *args, **kwargs): | |
Scheduler.transitions : transitive version of this function | ||
""" | ||
try: | ||
recommendations = {} # type: ignore | ||
worker_msgs = {} # type: ignore | ||
client_msgs = {} # type: ignore | ||
|
||
ts: TaskState = self.tasks.get(key) # type: ignore | ||
if ts is None: | ||
return recommendations, client_msgs, worker_msgs | ||
return {}, {}, {} | ||
start = ts._state | ||
if start == finish: | ||
return recommendations, client_msgs, worker_msgs | ||
return {}, {}, {} | ||
|
||
# Notes: | ||
# - in case of transition through released, this counter is incremented by 2 | ||
# - this increase happens before the actual transitions, so that it can | ||
# catch potential infinite recursions | ||
self.transition_counter += 1 | ||
if self.transition_counter_max: | ||
assert self.transition_counter < self.transition_counter_max | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be nice if this raised something like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, but scheduler doesn't have anything like InvalidTransitionError on the worker |
||
|
||
recommendations = {} # type: ignore | ||
worker_msgs = {} # type: ignore | ||
client_msgs = {} # type: ignore | ||
|
||
if self.plugins: | ||
dependents = set(ts.dependents) | ||
|
@@ -1451,7 +1463,7 @@ def _transition(self, key, finish: str, stimulus_id: str, *args, **kwargs): | |
recommendations, client_msgs, worker_msgs = func( | ||
key, stimulus_id, *args, **kwargs | ||
) # type: ignore | ||
self.transition_counter += 1 | ||
|
||
elif "released" not in start_finish: | ||
assert not args and not kwargs, (args, kwargs, start_finish) | ||
a_recs: dict | ||
|
@@ -3173,6 +3185,7 @@ def _to_dict(self, *, exclude: Container[str] = ()) -> dict: | |
info = super()._to_dict(exclude=exclude) | ||
extra = { | ||
"transition_log": self.transition_log, | ||
"transition_counter": self.transition_counter, | ||
"log": self.log, | ||
"tasks": self.tasks, | ||
"task_groups": self.task_groups, | ||
|
@@ -4496,6 +4509,8 @@ def validate_state(self, allow_overlap: bool = False) -> None: | |
actual_total_occupancy, | ||
self.total_occupancy, | ||
) | ||
if self.transition_counter_max: | ||
assert self.transition_counter < self.transition_counter_max | ||
|
||
################### | ||
# Manage Messages # | ||
|
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 should try to not clutter this file with stuff we only use for internal tests. Apart from tests I don't see the usefulness of having a global limit on the number of transitions
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.
Indeed, this is for tests only.