Backport of scheduling: prevent self-collision in dynamic port network offerings into release/1.5.x #16410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport
This PR is auto-generated from #16401 to be assessed for backporting due to the inclusion of the label backport/1.5.x.
The below text is copied from the body of the original PR.
Fixes #9506 #14850 (and several internally-tracked issues)
When the scheduler tries to find a placement for a new allocation, it iterates over a subset of nodes. For each node, we populate a
NetworkIndex
bitmap with the ports of all existing allocations and any other allocations already proposed as part of this same evaluation via itsSetAllocs
method. Then we make an "ask" of theNetworkIndex
inAssignPorts
for any ports we need and receive an "offer" in return. The offer will include both static ports and any dynamic port assignments.The
AssignPorts
method was written to support group networks, and it shares code that selects dynamic ports with the originalAssignTaskNetwork
code.AssignTaskNetwork
can request multiple ports from the bitmap at a time. ButAssignPorts
requests them one at a time and does not account for possible collisions, and doesn't return an error in that case.What happens next varies:
SetAllocs
, as we'd expect.SetAllocs
will detect the impossible state and the node will be rejected. This can have the puzzling behavior where a second task group for the job without any networking at all can hit a port collision error!It looks like this bug has existed since we implemented group networks, but there are several factors that add up to making the issue rare for many users yet frustratingly frequent for others:
spread
blocks, or (sometimes) jobs usingunique
constraints.For unlucky combinations of these factors, it's possible that case (3) happens repeatedly, preventing scheduling of a given job until a client state change (ex. restarting the agent so all its allocations are rescheduled elsewhere) re-opens the range of dynamic ports available.
This changeset:
AssignPorts
.AssignPorts
, expands coverage of this case for the deprecatedAssignTaskNetwork
, and tightens the dynamic port range in a scheduler test for spread scheduling to more easily detect this kind of problem in the future.String()
method toBitmap
so that any future "screaming" log lines have a human-readable list of used ports.