strophejs icon indicating copy to clipboard operation
strophejs copied to clipboard

Strophe.js resends the last request (send a duplicate) on refresh/close a page.

Open telmanagababov opened this issue 8 years ago • 15 comments

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 :

  1. We have 2 users: A and B
  2. User A sends a message to user B
  3. User B receives the message
  4. User A closes the page with a chat (or refreshes the page)
  5. (here is the bug) Before the closing, strophe.js sends a duplicated message to the user B
  6. 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

telmanagababov avatar Jan 18 '18 11:01 telmanagababov

Can you come up with a repeatable way of reproducing this behavior?

jcbrand avatar Jan 19 '18 09:01 jcbrand

The steps for which the issue is being reproduced for me are next:

  1. There are at least 2 users - User A and User B in same room
  2. Users A is connected via Tablet device (Android or IOS)
  3. Users A and B are buddies
  4. User A sends a private message to user B
  5. User B receives the message
  6. User A closes the page
  7. (here is the bug) Before the closing, strophe.js sends a duplicated message to the user B
  8. User B receives the duplicated message

It's not reproducing every time, but with a high probability, like 2 of 3 times.

telmanagababov avatar Jan 19 '18 10:01 telmanagababov

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.

jcbrand avatar Jan 20 '18 12:01 jcbrand

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.

telmanagababov avatar Jan 24 '18 15:01 telmanagababov

I'm talking about the id attribute of the message stanza, which is contained within the BOSH packet.

jcbrand avatar Jan 24 '18 16:01 jcbrand

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 ?

telmanagababov avatar Jan 25 '18 11:01 telmanagababov

How do you construct your message? You can always add an id yourself. Strophe has a method getUniqueId IIRC, which you can use.

jcbrand avatar Jan 25 '18 14:01 jcbrand

I got it. Seems like a solution for the problem. Thank you.

telmanagababov avatar Jan 25 '18 16:01 telmanagababov

Should I close the issue? Or is it supposed to be also fixed on the 'stophe.js' side in future ?

telmanagababov avatar Jan 25 '18 16:01 telmanagababov

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.

jcbrand avatar Jan 27 '18 10:01 jcbrand

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

nikul avatar May 28 '19 14:05 nikul

Hello,

ashfaq22iit avatar Jun 13 '19 12:06 ashfaq22iit

i am also facing same issue, please share solution if someone have.

ashfaq22iit avatar Jun 13 '19 12:06 ashfaq22iit

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!

nikul avatar Jun 13 '19 12:06 nikul

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 ?

ashfaq22iit avatar Aug 22 '19 09:08 ashfaq22iit