[SYNPY-1824] fix syn.sendMessage in async context#1370
Open
[SYNPY-1824] fix syn.sendMessage in async context#1370
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes notify_me_async in synapseutils.monitor so it can run under Python 3.14+ without triggering asyncio’s “active event loop prevents async-to-sync conversion” error when sending completion/failure notifications.
Changes:
- Replace
syn.sendMessage(...)withawait syn.sendMessage_async(...)inside the async retry/notification wrapper (success + exception paths).
Comments suppressed due to low confidence (1)
synapseutils/monitor.py:158
- Add unit coverage for
notify_me_asyncto prevent regressions (especially for Python 3.14+ event-loop behavior). There are existing tests for the syncnotifyMedecorator, but none validating that the async decorator awaitssyn.sendMessage_asyncon success and on retry/failure paths.
def notify_decorator(func):
@functools.wraps(func)
async def with_retry_and_messaging(*args, **kwargs):
attempt = 0
destination = syn.getUserProfile()["ownerId"]
while attempt <= retries:
try:
output = await func(*args, **kwargs)
await syn.sendMessage_async(
[destination],
messageSubject,
messageBody="Call to %s completed successfully!"
% func.__name__,
)
return output
except Exception as e:
syn.logger.exception(
f"Encountered a temporary Failure during execution. Will retry {retries - attempt} more times."
)
await syn.sendMessage_async(
[destination],
messageSubject,
messageBody=(
"Encountered a temporary Failure during upload. "
"Will retry %i more times. \n\n Error message was:\n%s\n\n%s"
% (retries - attempt, e, traceback.format_exc())
),
)
attempt += 1
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
andrewelamb
reviewed
Apr 27, 2026
andrewelamb
reviewed
Apr 27, 2026
andrewelamb
approved these changes
Apr 27, 2026
Contributor
|
@linglp LGTM! I just had a couple of questions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem:
See error:
This is affecting:
