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
| Field | Value |
|---|---|
| ID | CODE-0260 |
| Category | Generic |
| Severity | MEDIUM |
| CWE | CWE-758 |
| Confidence | MEDIUM |
| Impact | LOW |
| Likelihood | LOW |
| Exploitability | COMPLEX |
| Tags | pytorch, distributed, undefined behavior |
| OWASP | N/A |