Fix a race condition when querying op metadata#6309
Conversation
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Greptile SummaryThis PR fixes a race condition in Confidence Score: 5/5Safe to merge — the fix is minimal, correct, and directly tested. The race condition is precisely diagnosed and the fix is tight: capture-then-recheck is the standard pattern for this class of race. CPython's GIL guarantees that any thread observing No files require special attention. Important Files Changed
|
|
!build |
|
CI MESSAGE: [49276376]: BUILD STARTED |
| assert operator is not None | ||
| if init_spec := getattr(operator, "_init_spec", None): | ||
| init_spec(self._inputs, self._args) | ||
| if output_desc := operator._op_spec.OutputDesc(result_index): |
There was a problem hiding this comment.
[Nit] OpSpec::OutputDesc always returns a fixed 5-tuple (truthy), so the walrus check is equivalent to a non-None check here. Still, if output_desc := ... is not None: (or just unconditional indexing) would express the intent more clearly and stay correct if the API ever returns an empty container.
There was a problem hiding this comment.
If OutputDesc ever returns an empty tuple, we want this to be falsy because it would otherwise result on an IndexError on the next line
|
CI MESSAGE: [49276376]: BUILD FAILED |
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
|
!build |
|
CI MESSAGE: [49295377]: BUILD STARTED |
|
CI MESSAGE: [49295377]: BUILD PASSED |
Category:
Bug fix (non-breaking change which fixes an issue)
Description:
When getting the
ndim,dtypeorlayoutof an operator in dynamic mode, the invocation first checks that it has no result and if that's the case uses the operator to infer metadata statically. This can cause a race condition if another thread is executing the operator because the_operatorattribute of the invocation is set toNonewhen running is complete.Additional information:
Affected modules and functionalities:
Dynamic mode.
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-4668