Skip to content

Conversation

@samlurye
Copy link
Contributor

@samlurye samlurye commented Oct 28, 2025

Stack from ghstack (oldest at bottom):

The implementation of monarch.actor.Future uses loop.call_soon_threadsafe to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before call_soon_threadsafe executes the callback, then asyncio.exceptions.InvalidStateError will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.

Differential Revision: D85693875

NOTE FOR REVIEWERS: This PR has internal Meta-specific changes or comments, please review them on Phabricator!

The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!

[ghstack-poisoned]
samlurye added a commit that referenced this pull request Oct 28, 2025
The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!

ghstack-source-id: 319296138
Pull Request resolved: #1687
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 28, 2025
The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!

[ghstack-poisoned]
samlurye added a commit that referenced this pull request Oct 28, 2025
Pull Request resolved: #1687

The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.
ghstack-source-id: 319301656
@exported-using-ghexport

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!
The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!

[ghstack-poisoned]
samlurye added a commit that referenced this pull request Oct 28, 2025
Pull Request resolved: #1687

The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.
ghstack-source-id: 319328566
@exported-using-ghexport

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!
The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!

[ghstack-poisoned]
samlurye added a commit that referenced this pull request Oct 29, 2025
Pull Request resolved: #1687

The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.
ghstack-source-id: 319407775
@exported-using-ghexport

Differential Revision: [D85693875](https://our.internmc.facebook.com/intern/diff/D85693875/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D85693875/)!
@meta-codesync meta-codesync bot closed this in dd2fe54 Oct 29, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 29, 2025

This pull request has been merged in dd2fe54.

AlirezaShamsoshoara pushed a commit to AlirezaShamsoshoara/monarch that referenced this pull request Oct 30, 2025
Summary:
Pull Request resolved: meta-pytorch#1687

The implementation of `monarch.actor.Future` uses `loop.call_soon_threadsafe` to set a value/exception on an underlying asyncio future. But if the caller cancelled the asyncio future before `call_soon_threadsafe` executes the callback, then `asyncio.exceptions.InvalidStateError` will be logged, which is noisy and misleading.

This diff solves the issue by checking whether the future is already resolved/cancelled from inside the callback.
ghstack-source-id: 319407775
exported-using-ghexport

Reviewed By: zdevito

Differential Revision: D85693875

fbshipit-source-id: eb515cd65e78fcbb853909af3ba96196c1315c98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants