Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Switch from for loop to while
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Dec 13, 2022
1 parent bbc57e7 commit 28c930b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
10 changes: 4 additions & 6 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,9 +1344,8 @@ async def exchange_third_party_invite(

EventValidator().validate_builder(builder)

# Try 2 times, the first one could fail with PartialStateConflictError
# in send_membership_event, cf comment in except block.
for _ in range(2):
# Try until success, send_membership_event could fail with PartialStateConflictError
while True:
try:
(
event,
Expand Down Expand Up @@ -1418,9 +1417,8 @@ async def on_exchange_third_party_invite_request(
room_version_obj, event_dict
)

# Try 2 times, the first one could fail with PartialStateConflictError
# in send_membership_event, cf comment in except block.
for _ in range(2):
# Try until success, send_membership_event could fail with PartialStateConflictError
while True:
try:
(
event,
Expand Down
10 changes: 4 additions & 6 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,8 @@ async def create_and_send_nonmember_event(
event.internal_metadata.stream_ordering,
)

# Try 2 times, the first one could fail with PartialStateConflictError
# in handle_new_client_event, cf comment in except block.
for _ in range(2):
# Try until success, handle_new_client_event could fail with PartialStateConflictError
while True:
try:
event, context = await self.create_event(
requester,
Expand Down Expand Up @@ -2010,9 +2009,8 @@ async def _send_dummy_event_for_room(self, room_id: str) -> bool:
for user_id in members:
requester = create_requester(user_id, authenticated_entity=self.server_name)
try:
# Try 2 times, the first one could fail with PartialStateConflictError
# in handle_new_client_event, cf comment in except block.
for _ in range(2):
# Try until success, handle_new_client_event could fail with PartialStateConflictError
while True:
try:
event, context = await self.create_event(
requester,
Expand Down
10 changes: 4 additions & 6 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,8 @@ async def _local_membership_update(
event_pos = await self.store.get_position_for_event(existing_event_id)
return existing_event_id, event_pos.stream

# Try 2 times, the first one could fail with PartialStateConflictError,
# cf comment in except block.
for _ in range(2):
# Try until success, handle_new_client_event could fail with PartialStateConflictError
while True:
try:
event, context = await self.event_creation_handler.create_event(
requester,
Expand Down Expand Up @@ -1884,9 +1883,8 @@ async def _generate_local_out_of_band_leave(
list(previous_membership_event.auth_event_ids()) + prev_event_ids
)

# Try 2 times, the first one could fail with PartialStateConflictError
# in handle_new_client_event, cf comment in except block.
for _ in range(2):
# Try until success, handle_new_client_event could fail with PartialStateConflictError
while True:
try:
event, context = await self.event_creation_handler.create_event(
requester,
Expand Down

0 comments on commit 28c930b

Please sign in to comment.