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

Commit

Permalink
Make StreamToken and RoomStreamToken methods propagate cancellati…
Browse files Browse the repository at this point in the history
…ons (#12366)

`StreamToken.from_string` and `RoomStreamToken.parse` are both async
methods that could be cancelled. These methods must not replace
`CancelledError`s with `SynapseError`s.

Signed-off-by: Sean Quah <seanq@element.io>
  • Loading branch information
squahtx authored Apr 5, 2022
1 parent 9c4c499 commit 31c1209
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/12366.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make `StreamToken.from_string` and `RoomStreamToken.parse` propagate cancellations instead of replacing them with `SynapseError`s.
5 changes: 5 additions & 0 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from unpaddedbase64 import decode_base64
from zope.interface import Interface

from twisted.internet.defer import CancelledError
from twisted.internet.interfaces import (
IReactorCore,
IReactorPluggableNameResolver,
Expand Down Expand Up @@ -540,6 +541,8 @@ async def parse(cls, store: "PurgeEventsStore", string: str) -> "RoomStreamToken
stream=stream,
instance_map=frozendict(instance_map),
)
except CancelledError:
raise
except Exception:
pass
raise SynapseError(400, "Invalid room stream token %r" % (string,))
Expand Down Expand Up @@ -705,6 +708,8 @@ async def from_string(cls, store: "DataStore", string: str) -> "StreamToken":
return cls(
await RoomStreamToken.parse(store, keys[0]), *(int(k) for k in keys[1:])
)
except CancelledError:
raise
except Exception:
raise SynapseError(400, "Invalid stream token")

Expand Down

0 comments on commit 31c1209

Please sign in to comment.