Strophe.js resends the last request (send a duplicate) on refresh/close a page.
Actual behavior: Sometimes Strophe.js sends duplicate requests on close/refresh page. Expected behavior: It is expected, that Strophe shouldn't resend last message on unload, since it was delivered already.
The issue reproduces sometimes on Desktop browsers, and it reproduces much easier on Tablets (Android / IOS).
Steps to reproduce :
- We have 2 users: A and B
- User A sends a message to user B
- User B receives the message
- User A closes the page with a chat (or refreshes the page)
- (here is the bug) Before the closing, strophe.js sends a duplicated message to the user B
- User B receives the duplicated message
Investigation: The duplicate request is being sent before the firing of 'unload' or 'beforeunload' events, so any manipulations on the client side, like disconnecting / pausing / cleaning requests / etc. don't work. Thus I think it should be fixed on the 'strophe.js' side.
Also I found several similar requests regarding to this issue, that weren't solved, but probably can give some additional info regarding to the issue:
- https://stackoverflow.com/questions/21337239/on-page-unload-strophe-js-sends-request-twice-why
- https://groups.google.com/forum/#!topic/strophe/Z4oInwY8IaY
- https://stackoverflow.com/questions/7752475/strophe-sending-double-request-on-page-unload
- https://github.com/strophe/strophejs/issues/123
Can you come up with a repeatable way of reproducing this behavior?
The steps for which the issue is being reproduced for me are next:
- There are at least 2 users - User A and User B in same room
- Users A is connected via Tablet device (Android or IOS)
- Users A and B are buddies
- User A sends a private message to user B
- User B receives the message
- User A closes the page
- (here is the bug) Before the closing, strophe.js sends a duplicated message to the user B
- User B receives the duplicated message
It's not reproducing every time, but with a high probability, like 2 of 3 times.
So it only happens with mobile users, and only some of the time?
Why don't you just check for duplicate messages on the receiving end and not show them? The message stanza has an id attribute that you can check for.
For me it reproduces on (Tablet + Tablet) or on (Tablet + Desktop).
Not sure about checking the duplicate id. I see only rid in sending messages, but no any id in responses.
I use Openfire on a server side, and didn't see any such configurations there. Also checked the BOSH docs - https://xmpp.org/extensions/xep-0124.html and didn't find any requirements regarding to id in responses.
Please correct me if I am wrong or missed something.
I'm talking about the id attribute of the message stanza, which is contained within the BOSH packet.
Hi again, Thanks for the repsonse,
Could you please have a look at the example below:
I sent a message from player_a to player_b
Here is a request message:
<body rid='3447530382' xmlns='http://jabber.org/protocol/httpbind' sid='54781db1'><message to='player_b-xxx@xxx/stream' type='chat' xmlns='jabber:client'><body>message-sample</body></message></body>
And here is a response:
<body xmlns='http://jabber.org/protocol/httpbind'><message xmlns="jabber:client" to="'player_b-xxx@xxx/stream" type="chat" from="'player_a-xxx@xxx/stream"><body>message-sample</body></message></body>
I don't see any id in message. Is it a problem in usage of strophe.js, or am I messed something again ?
How do you construct your message? You can always add an id yourself. Strophe has a method getUniqueId IIRC, which you can use.
I got it. Seems like a solution for the problem. Thank you.
Should I close the issue? Or is it supposed to be also fixed on the 'stophe.js' side in future ?
For the moment I don't think this is something to fix within strophe.js. For that to happen, we would need a reproducible test for it.
hi @telmanagababov i am facing same issue of sending message twice after page load, what can be solution for this? Can you share you code please?
Thanks
Hello,
i am also facing same issue, please share solution if someone have.
i am also facing same issue, please share solution if someone have. Hi,
Do following changes in strophe.js
Comment below code at approx. line 2624
if (req.sends > 1) {
// Using a cube of the retry number creats a nicely
// expanding retry window
var backoff = Math.pow(req.sends, 3) * 1000;
setTimeout(sendFunc, backoff);
} else {
sendFunc();
}
Then add below code after comment,
if (req.sends == 0) {
sendFunc();
}
Hope this help!
i am also facing same issue, please share solution if someone have. Hi,
Do following changes in strophe.js Comment below code at approx. line 2624
if (req.sends > 1) { // Using a cube of the retry number creats a nicely // expanding retry window var backoff = Math.pow(req.sends, 3) * 1000; setTimeout(sendFunc, backoff); } else { sendFunc(); }Then add below code after comment,if (req.sends == 0) { sendFunc(); }Hope this help!
Hello thanks for your support i have try this and also update strophe plugin. but again facing same issue. there is any other solution ?