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

Error: Retrying in Invalid date… #82

Closed
dogcalas opened this issue Jan 31, 2020 · 23 comments
Closed

Error: Retrying in Invalid date… #82

dogcalas opened this issue Jan 31, 2020 · 23 comments
Assignees
Labels
bug Something isn't working Requires Investigation Awaiting more visibility on issue and possible solutions

Comments

@dogcalas
Copy link

dogcalas commented Jan 31, 2020

Sulla stop working after a while, nothing came out on console but chromium windows show a
"Retrying in Invalid date…" error.

Steps to reproduce the behavior:

  1. Run Sulla Code
  2. After a while a the whatsapp windows shows this error message.

sulla-hotfix version
"version": "1.6.15",
Whatsapp version
Debug Info { WA_VERSION: '0.4.315',

Screenshots
image

Host (please complete the following information):

  • OS: [Linux Mint]
  • Browser [Chromium]
  • Version [79.0.3945.79 ]
@smashah
Copy link
Member

smashah commented Jan 31, 2020

Hey @dogcalas can you share the whole debug info

@dogcalas
Copy link
Author

✔ Initializing whatsapp
Debug Info { WA_VERSION: '0.4.315',
PAGE_UA:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.131 Safari/537.36' }
✔ Authenticating
✔ Whatsapp is ready

@nicolaubrasil
Copy link

nicolaubrasil commented Feb 1, 2020

Same problem here. :( Any solution?

✔ Initializing whatsapp
Debug Info { WA_VERSION: '0.4.315',
PAGE_UA:
'WhatsApp/0.4.315 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36' }
✔ Authenticating
✔ Whatsapp is ready

@CosmicSnow
Copy link

CosmicSnow commented Feb 2, 2020

Just for the knowledge, I'm having the same problem,
The session is working fine, but if, for some reason, my smartphone disconnects, or if my whatsapp app keeps idle for too long, I get this problem, which says trying to connect again in Invalid date...

there is no error on the terminal.
I just saw the error when I set headless to false.

@smashah smashah self-assigned this Feb 2, 2020
@smashah smashah added the Requires Investigation Awaiting more visibility on issue and possible solutions label Feb 2, 2020
@ChrisB0701
Copy link

Same here. Once there are no incoming or outgoing messages for more than a few minutes, the above mentioned message is shown.

@smashah
Copy link
Member

smashah commented Feb 3, 2020

Just gonna leave my notes here.

Ran in console:

l10n.localeStrings.en[0].filter(x=>x.includes('Retrying in'))
//result: ["Retrying in __duration__…", "Retrying in __number__ second…"]
l10n.localeStrings.en[0].findIndex((x,y)=>x.includes('Retrying in'))
//result: 964
l10n.localeStrings.en[0].findIndex((x,y)=>x.includes('Retrying in __n'))
//result: 985

Now I use these indexes in the main app code to find out what results in the triggering of these 2 string identifiers to be rendered.

Open https://web.whatsapp.com/app.9d707d8cc13bce7894d2.js in sources tab. Beutify.

//ctrl+f: 964
//I'm now inside some sort of react component
//ref: "bafjeggiaj"
var s = this.state.retriable;
                    if (s) {
                        var c = m.default.retryTimestamp - Date.now();
                        if (c < 1)
                            n = l10n.t(963),
                            (0,
                            r.default)(function() {
                                return m.default.poke()
                            });
                        else if (c < 6e4) {
                            var l = Math.ceil(c / 1e3);
                            n = l10n.t(965, {
                                number: l,
                                _plural: l
                            })
                        } else
                            n = l10n.t(964, {
                                duration: i.default.duration(c).humanize()
                            })
                    }

Looks like the invalid date is a result of c being humanized(). Doesn't look like a fundamental issue and the good news is WAWEB thinks it's still retriable.

Let's figure out how we can get .humanize() to result in 'invalid date'. Pretty sure this is momentjs. Let's double check.

//scroll up until we find the definition of i
i = v(n("dgdjiicfdg"))

//in console
const i = webpackJsonp([],null,["dgdjiicfdg"])
//returns: ƒ n(){return t.apply(null,arguments)}

//hmm ok this is a function
i()

//returns:
y {_isAMomentObject: true, _isUTC: false, _pf: {}, _locale: O, _d: Mon Feb 03 2020 16:07:18 GMT+0000 (Greenwich Mean Time), …}

Ok _isAMomentObject:true proves this is momentjs.

Based on this https://momentjscom.readthedocs.io/en/latest/moment/08-durations/03-humanize/#momentdurationhumanize

moment.duration.invalid().humanize(); // Invalid Date

hmm ok, so you have to explicitly force invalid date?

Based on
https://github.com/moment/moment/blob/2e2a5b35439665d4b0200143d808a7c26d6cd30f/src/lib/duration/humanize.js#L73

No. If the moment date isValid() == false then it results in invalid date. What makes a date invalid? Turns out a lot of things.

https://github.com/moment/moment/blob/2e2a5b35439665d4b0200143d808a7c26d6cd30f/src/lib/duration/valid.js

I am unable to recreate the issue. Now, @dogcalas @nicolaubrasil @CosmicSnow @ChrisB0701

Can you all please share the following information:

  1. What happens when you press retry now?
  2. Is the waweb instance and your phone in the same timezone?
  3. What do you get when you run Date.now() in the waweb puppeteer page console?
  4. Are you completely certain that your phone + instance are connected.
  5. What is the state when this happens? You can listen to state like this:
    https://github.com/smashah/sulla/blob/377b00d4ca9b99676d5e4161053ed10208c4fcb5/demo/index.ts#L35

@ChrisB0701
Copy link

ChrisB0701 commented Feb 4, 2020

Thanks for looking into this! I have not been able to execute all of the requested steps but here are the results of what I could test so far. I'm testing with the locally installed chrome.exe on Windows 10.

1. What happens when you press retry now?
Nothing happens. No retry is executed and the screen still shows "Retrying again in: Invalid date". The console shows the following error:
waweb001
However, when I stop and restart the script, the session is still valid and no new authentication is required.

2. Is the waweb instance and your phone in the same timezone?
Yes. Timezone and time are the same.

3. What do you get when you run Date.now() in the waweb puppeteer page console?
The function returns a UNIX timestamp that matches the current date and time of my PC.

4. Are you completely certain that your phone + instance are connected.
Yes

5. What is the state when this happens? You can listen to state like this:
The event is not triggered. But I'm not running the browser in English.

What I also tested: I manually opened WA Web in Chrome and started a normal session without any sulla-hotfix context. This session stayed connected for more than 12 hours until I closed it myself. Then I used the same device to start a WA Web session within sulla-hotfix using the same chrome.exe and it got disconnected within just a few minutes.

@dogcalas
Copy link
Author

dogcalas commented Feb 4, 2020

I believe this issue isn't related to invalid dates. When this error comes, can be seen in the browser an infinite attempts of ws connections, but they are all rejected. All connections attempts are closed by the server.
The invalid date message comes because whatsapp is trying to find a retry timestamp in m.default.retryTimestamp but is undefined.

  1. What happens when you press retry now?
    The following log is shown in console:
    Websocket is closed before the connection is established.

  2. Is the waweb instance and your phone in the same timezone?
    Yes

  3. What do you get when you run Date.now() in the waweb puppeteer page console?
    It returns a now timestamp.

  4. Are you completely certain that your phone + instance are connected.
    Completely sure

  5. What is the state when this happens? You can listen to state like this
    After added state event code, I haven't received any error until now . I still waiting...

@smashah
Copy link
Member

smashah commented Feb 4, 2020

@dogcalas @ChrisB0701 Can you check in your network tab and see what the status code is of the WebSocket connection.

Also, what is the status of your bots? I.e is it in production and being used heavily, just in local development etc.?

@ChrisB0701
Copy link

Today I noticed this additional error in the browser debug console after the "Retrying in invalid date..." message appeared:
4app.e01fef611b286eaf8de8.js:2 WebSocket connection to 'wss://web.whatsapp.com/ws' failed: Error during WebSocket handshake: Unexpected response code: 502

The network console was full of the following:
waweb002

I tested it with two bots:

  1. is used heavily and as long as there is traffic (meaning incoming and outgoing messages) wa web stays connected. It seems to disconnect once there is less or no activity for a longer period of time.
  2. is not used at all. I didn't send and receive any messages. This session disconnects much earlier than the first one, mabye due to the lack of activity?

@smashah
Copy link
Member

smashah commented Feb 5, 2020

@ChrisB0701 thanks. Few observations:

  1. Looks like WhatsApp is screwing with your ws and blocking it?
  2. The user agent for the is messed up. @ChrisB0701 can you please share your debug info and your create code as well.

@ChrisB0701
Copy link

Looks like WhatsApp is screwing with your ws and blocking it?

Seems so, but I can't figure out the reason. As I said - after restarting the script, the session is still valid and the connection is re-established.

The user agent for the is messed up. @ChrisB0701 can you please share your debug info and your create code as well.

Here is my debug info:

√ Initializing whatsapp
[2020-02-06T11:15:10.327Z] Debug Info {
  WA_VERSION: '0.4.612',
  PAGE_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
  SULLA_HOTFIX_VERSION: '1.7.5',
  BROWSER_VERSION: 'Chrome/79.0.3945.130'
}
√ Authenticating
√ Whatsapp is ready

This is my create code:

create('session' + config.uniqueSessionId,
	{
		executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
		headless: false
	},
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36').then(client => start(client));

Sorry, I'm no expert on the UA stuff. I copied the user agent info out of my chrome. Did I do something wrong here?

@ChrisB0701
Copy link

As mentioned above, unfortunately the state does not change. Any idea on another way to identify this event? Then I could kill and restart the session.

@ChrisB0701
Copy link

ChrisB0701 commented Feb 8, 2020

So I was not able to figure out the reason for this. I assume it is connected with the puppeteer environment: If I open wa web on the same machine in a regular chrome session without sulla and puppeteer, the connection is not lost. If I open wa web within sulla on the same machine and with the same wa account, the connection is lost and the above mentioned message is shown sooner or later.

However, I'm using this workaround right now: Though the onStateChange method is not triggered, client.getConnectionState() returns "OPENING" once the "Retrying in..." screen appears. Thus, I'm regularly checking the connection state with getConnectionState() and as soon as it returns something different to "CONNECTED", I kill the session and restart the session again. I don't know, if this might help anyone with the same issue...

@smashah
Copy link
Member

smashah commented Feb 8, 2020

@ChrisB0701
Copy link

@ChrisB0701 you can listen to state changes with this:

https://github.com/smashah/sulla/blob/82ee145b9d83222aa506ff3bfc72a9aacd9164da/demo/index.ts#L43

I know, but for whatever reason, this event is not triggered when the "Retrying in..." screen appears. At least not in my setup... I don't know why.

@smashah
Copy link
Member

smashah commented Feb 8, 2020

@ChrisB0701 can you join the discord so I can remote desktop with you since I'm not able to reproduce.

https://discord.gg/f7dvea

Go to the sulla-hotfix channel

@ChrisB0701
Copy link

@ChrisB0701 you can listen to state changes with this:

https://github.com/smashah/sulla/blob/82ee145b9d83222aa506ff3bfc72a9aacd9164da/demo/index.ts#L43

I think, I had an error in my usage of the onStateChanged method. In my first implementation it was not firing anything at all. Now I got it working and since then there hasn't been any disconnects. There are regularly sequences of "OPENING - PAIRING - CONNECTED" but the connection has been re-established in all cases so far.

I will keep you posted and let you know about the result, once there is another disconnect. Until then, I don't think I have to bother you in discord. :) But thanks anyway for the offer!

@smashah
Copy link
Member

smashah commented Feb 11, 2020

@ChrisB0701 @dogcalas @CosmicSnow @nicolaubrasil Hi all, can you try new v.1.7.10 and let me know if this issue is fixed.

Thanks

@smashah smashah added the bug Something isn't working label Feb 11, 2020
@dogcalas
Copy link
Author

dogcalas commented Feb 11, 2020

Thank you @smashah, I will let you know.

@ChrisB0701
Copy link

Thanks, @smashah! Actually I didn't have any disconnects in the last three days still using the old v.1.7.5. I don't know if there was any fix by WA. However, I will update to v.1.7.10 and let you know.

@ChrisB0701
Copy link

I didn't have the "Retrying in... Invalid date" screen in the last two days. So I assume it's working now. Thank you @smashah very much for your great work in this project! I bought you some coffee! :)

@smashah
Copy link
Member

smashah commented Feb 14, 2020

@ChrisB0701 awesome! your clue that helped me figure it out was:

I think, I had an error in my usage of the onStateChanged method. In my first implementation it was not firing anything at all. Now I got it working and since then there hasn't been any disconnects. There are regularly sequences of "OPENING - PAIRING - CONNECTED" but the connection has been re-established in all cases so far.

Any unused listeners cause issues so in the middleware I will make sure only onMessage is present.

Thanks for the coffee! Definitely needed it over the last few days! I'll close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Requires Investigation Awaiting more visibility on issue and possible solutions
Projects
None yet
Development

No branches or pull requests

5 participants