Skip to content

PyTorch Distributed Request Without Waiting

Description

Not waiting for requests in PyTorch distributed operations can lead to undefined behavior. The `torch.distributed.irecv` and `torch.distributed.isend` functions return a request object that must be waited on using the `wait` method to ensure the operation is complete.

Examples

Insecure Code

python
req = torch.distributed.isend(tensor, dst)

Secure Code

python
req = torch.distributed.isend(tensor, dst)
req.wait()

Remediation

Add a call to the `wait` method on the request object returned by `torch.distributed.irecv` or `torch.distributed.isend` to ensure the operation is complete.

Rule Details

FieldValue
IDCODE-0260
CategoryGeneric
SeverityMEDIUM
CWECWE-758
ConfidenceMEDIUM
ImpactLOW
LikelihoodLOW
ExploitabilityCOMPLEX
Tagspytorch, distributed, undefined behavior
OWASPN/A

References