Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec gives bad advice on generating transaction IDs #1706

Closed
tulir opened this issue Jan 9, 2024 · 2 comments · Fixed by #1888
Closed

Spec gives bad advice on generating transaction IDs #1706

tulir opened this issue Jan 9, 2024 · 2 comments · Fixed by #1888
Labels
improvement An idea/future MSC for the spec

Comments

@tulir
Copy link
Member

tulir commented Jan 9, 2024

In https://spec.matrix.org/v1.9/client-server-api/#transaction-identifiers the spec says (emphasis mine)

From the client perspective, after the request has finished, the {txnId} value should be changed by for the next request (how is not specified; a monotonically increasing integer is recommended).

Recently two developers have encountered issues with transaction IDs ([1], [2]). In both cases, it turned out they had followed the recommendation from the spec and used a plain monotonically increasing integer as the transaction ID. Counting from 0 means there are conflicts whenever the counter resets, and persisting counters is error-prone. The first case had a persistence bug, the second case was creating a new access token on each startup, but MSC3970 broke that by changing transaction ID scope from access token to device ID.

Something like concatenating the current timestamp with a monotonically increasing integer would be a much safer recommendation.

@TheArcaneBrony
Copy link

Personally using version 4 GUIDs as tnxIds, I'd say anything that can be reasonably guaranteed to be unique would be a fairly safe recommendation.
Perhaps alternatives could be listed in the spec?

@turt2live turt2live added the improvement An idea/future MSC for the spec label Jan 9, 2024
@Johennes
Copy link
Contributor

For reference:

Johennes added a commit to Johennes/matrix-spec that referenced this issue Jun 25, 2024
Fixes: matrix-org#1706
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement An idea/future MSC for the spec
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants