Comments (14)
In that case then it could have just been a coincidence. I'll keep investigating and I'll let you know if I discover something more concrete.
from ement.el.
Ok, 2763bd6 initializes a new session's transaction ID to a large, pseudorandom integer. It should probably prevent any issues with Pantalaimon as @mrmekon described. You can either disconnect/reconnect to initialize a new session, or you can manually set your session's transaction ID to any very large integer by evaluating the appropriate Lisp expression.
The warnings may still happen occasionally when the server responds out-of-order to sending a new event; I'm not sure of the best way to solve that yet. But I could probably just disable the warning by default now; it's mostly served its purpose by bringing this issue to our attention.
from ement.el.
@alphapapa sure, I'll give that a try and I'll let you know what happens. You may see me on the Ement.el chat room collecting test data in that case :)
from ement.el.
Hi,
Thanks for the kind words. I'm glad it's useful to you.
I pushed an update to the warning message to help clarify what's going on, and to update the variable name. I should probably also update the transaction IDs to initialize them with the current timestamp, which I was told is what Element does, which should help prevent the reuse problem.
However, if there's some kind of unexpected interaction causing this to happen more frequently when using Pantalaimon, I don't know what's going on there.
from ement.el.
Hi, thanks for looking into this and for clarifying the warning message.
As an update, I've noticed what seems to cause this. I am trying to use Ement.el as much as possible, but for things like sending file attachments I'm jumping back to the Element web app. I noticed that after I send a message in a room on Element, the next time I send a message in Ement.el it'll come up with this warning.
from ement.el.
Well, given that we already have a send-image command, a send-file one will be easy to add. I just haven't needed it yet, myself, so I haven't bothered to add it.
I can't see how those two events could be related to this problem. Ement.el and Element should not be using the same access token (unless you manually copied the token from one client to the other, which surely you didn't), and transaction IDs are scoped to the tokens, so it shouldn't be possible for the two clients to interfere with each other. Are you sure that it's not just a coincidence?
The only alternative I can think of would be if Pantalaimon were doing something weird with tokens or transaction IDs. But other users have been using it without reporting such issues, and it seems unlikely that it would do something like that.
from ement.el.
I was getting this frequently as well. I'm not an expert on Matrix by any means, so take this with a grain of salt:
It looks like my Pantalaimon session maintains a persistent device ID to the homeserver, but Ement.el generates a new device ID every time it connects to the proxy. This is presumably because ement-save-sessions
is nil, and enabling that might fix it.
The result is that the session's transaction-id resets to 0 on every reconnect. Ement.el sends messages to the URL https://.../m.room.message/<transaction id>
. Once transaction-id rolls back to zero, someone along the chain (I'm not sure if it's Pantalaimon or the homeserver) detects duplicate transactions from the same device and rejects them. Ement.el increments transaction-id even if it fails to send, so if you send enough messages you will eventually get a unique transaction-id and they will start going through again.
Even if saving the session works, I personally want the ability to blow away the cached session file and restart, so I've patched my local copy to include Ement.el's current device-id along with the transaction-id in the post URLs. I don't know if that's even legal by the API's specs, but it seems to work.
Here's the (almost entirely untested) patch I'm using:
From 5e248ce16e61caaacc8cdf98b5602f9724d8bf1b Mon Sep 17 00:00:00 2001
From: Trevor Bentley <[email protected]>
Date: Fri, 24 Sep 2021 17:35:54 +0200
Subject: [PATCH] use device-id in conjunction with transaction-id
---
ement-room.el | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/ement-room.el b/ement-room.el
index 84b39cb..821c97c 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -818,8 +818,10 @@ Interactively, set the current buffer's ROOM's TOPIC."
(message "Uploaded file %S. Sending message..." file)
(pcase-let* (((map ('content_uri content-uri)) data)
((cl-struct ement-room (id room-id)) room)
- (endpoint (format "rooms/%s/send/%s/%s" (url-hexify-string room-id)
- "m.room.message" (cl-incf (ement-session-transaction-id session))))
+ (endpoint (format "rooms/%s/send/%s/%s-%s" (url-hexify-string room-id)
+ "m.room.message"
+ (url-hexify-string (ement-session-device-id session))
+ (cl-incf (ement-session-transaction-id session))))
;; TODO: Image height/width (maybe not easy to get in Emacs).
(content (ement-alist "msgtype" "m.image"
"url" content-uri
@@ -1153,7 +1155,8 @@ the content. (e.g. see `ement-room-send-org-filter')."
(cl-assert (or (not formatted-body) (not (string-empty-p formatted-body))))
(pcase-let* (((cl-struct ement-room (id room-id) (local (map buffer))) room)
(window (when buffer (get-buffer-window buffer)))
- (endpoint (format "rooms/%s/send/m.room.message/%s" (url-hexify-string room-id)
+ (endpoint (format "rooms/%s/send/m.room.message/%s-%s" (url-hexify-string room-id)
+ (url-hexify-string (ement-session-device-id session))
(cl-incf (ement-session-transaction-id session))))
(content (ement-aprog1
(ement-alist "msgtype" "m.text"
@@ -1198,7 +1201,8 @@ the content. (e.g. see `ement-room-send-org-filter')."
(cl-assert (not (string-empty-p body)))
(pcase-let* (((cl-struct ement-room (id room-id) (local (map buffer))) room)
(window (when buffer (get-buffer-window buffer)))
- (endpoint (format "rooms/%s/send/m.room.message/%s" (url-hexify-string room-id)
+ (endpoint (format "rooms/%s/send/m.room.message/%s-%s" (url-hexify-string room-id)
+ (url-hexify-string (ement-session-device-id session))
(cl-incf (ement-session-transaction-id session))))
(content (ement-aprog1
(ement-alist "msgtype" "m.emote"
@@ -1278,8 +1282,10 @@ The message must be one sent by the local user."
(user-error "To delete a message, use command `ement-room-delete-message'"))
(when (yes-or-no-p (format "Edit message to: %S? " body))
(list event ement-room ement-session body)))))))
- (let* ((endpoint (format "rooms/%s/send/%s/%s" (url-hexify-string (ement-room-id room))
- "m.room.message" (cl-incf (ement-session-transaction-id session))))
+ (let* ((endpoint (format "rooms/%s/send/%s/%s-%s" (url-hexify-string (ement-room-id room))
+ "m.room.message"
+ (url-hexify-string (ement-session-device-id session))
+ (cl-incf (ement-session-transaction-id session))))
(new-content (ement-alist "body" body
"msgtype" "m.text"))
(_ (when ement-room-send-message-filter
@@ -1307,8 +1313,9 @@ The message must be one sent by the local user."
(user-error "Message not deleted"))))
(pcase-let* (((cl-struct ement-event (id event-id)) event)
((cl-struct ement-room (id room-id)) room)
- (endpoint (format "rooms/%s/redact/%s/%s"
+ (endpoint (format "rooms/%s/redact/%s/%s-%s"
(url-hexify-string room-id) (url-hexify-string event-id)
+ (url-hexify-string (ement-session-device-id ement-session))
(cl-incf (ement-session-transaction-id ement-session))))
(content (if reason
(ement-alist "reason" reason)
@@ -1373,7 +1380,8 @@ reaction string, e.g. \"👍\"."
;; hl-line-mode is enabled, it only returns the hl-line face.
((cl-struct ement-event (id event-id)) event)
((cl-struct ement-room (id room-id)) ement-room)
- (endpoint (format "rooms/%s/send/m.reaction/%s" (url-hexify-string room-id)
+ (endpoint (format "rooms/%s/send/m.reaction/%s-%s" (url-hexify-string room-id)
+ (url-hexify-string (ement-session-device-id ement-session))
(cl-incf (ement-session-transaction-id ement-session))))
(content (ement-alist "m.relates_to"
(ement-alist "rel_type" "m.annotation"
--
2.32.0
from ement.el.
Hi @mrmekon, that's very interesting, thanks for the detailed explanation.
I've been using Ement.el fairly regularly and I still get this issue occasionally, however now it doesn't seem to prevent the message from being sent. I do however sometimes have problems where a message continually fails to send and there's no warning. I haven't raised an issue yet as I haven't had time to debug it.
I'll give your patch a try to see if that helps!
from ement.el.
Hi Trevor,
Looks like you're going to make me pull out the spec and dig into device IDs. :) Well, I was going to have to do that at some point. Thanks.
As @treed (I think it was Ted) mentioned to me, it might be good to use the current timestamp in the transaction IDs, which would probably make these conflicts nearly impossible. (The Matrix spec doesn't seem to give much guidance regarding what clients should use for transaction IDs, so I started with an integer from 1, but that can occasionally lead to issues like this.)
I do however sometimes have problems where a message continually fails to send and there's no warning.
That's probably the transaction ID issue. Using the timestamp in the ID will probably solve that.
from ement.el.
Yeah, I decided to see how Element handles this case and found that date bit in the SDK code. It seems a reasonable enough fix to me.
from ement.el.
Just a quick update: I pulled these changes and have been using Ement.el a lot since then. I still get the warnings quite frequently (perhaps once every 20 messages on average) but as yet nothing has failed to send.
So it certainly looks like the situation has improved.
from ement.el.
@polaris64 Are you using the matrix.org homeserver or a different one?
from ement.el.
@alphapapa, yes the matrix.org homeserver, encrypted rooms via Pantalaimon
from ement.el.
@polaris64 Thanks. If you have the inclination, I'd be interested to know if you get these warnings when you connect without Pantalaimon and use non-encrypted rooms. It'd be helpful to know if the problem is isolated to or exacerbated by Pantalaimon.
from ement.el.
Related Issues (20)
- only the last disconnected session is remembered when `(ement-save-sessions)` is set to `t` HOT 2
- Errors When Trying to use ement-directory HOT 12
- Error running timer ‘plz--respond’: (ement-api-error "500: nil") while trying pantalaimon HOT 3
- User-specified percentage image scaling HOT 3
- Blank lines not displayed in message reply HOT 3
- Replacement events are inserted into the room based on the replacement timestamp rather the original event's? HOT 1
- Room list visibility cache includes event data HOT 2
- Avoid `ement-room-list-auto-update' repeatedly rebuilding the buffer if it is not being disaplayed HOT 2
- Jumping to an edited message from the notifications buffer doesn't work
- Lisp error signing into Beeper/Matrix via Pantalaimon HOT 7
- Gentoo: Symbol’s function definition is void: libxml-parse-html-region HOT 3
- [FEATURE] add "Discord" format to ement-room-message-format-spec HOT 1
- ement-directory-search signals error when no rooms found HOT 2
- @usernames aren't linked at the beginnings of lines, except for the first line HOT 1
- Consider swapping the M-RET and S-<return> bindings HOT 7
- Compilation error on Emacs 27 HOT 1
- `ement-send-reaction` + `emoji-search` signals wrong-number-of-arguments error [Emacs 30] HOT 7
- Restore the ability for an active region to determine the quoted text in a reply HOT 1
- Edition of messages breaks reactions HOT 1
- Eager macro-expansion failure: (error "Unknown cl-type pattern: (cl-type ement-room)") HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ement.el.