Schmavery/facebook-chat-api

Error 1357004 in markAsRead and getUserInfo after a few days of uptime

LokeofAsgard opened this issue · 7 comments

So after my bot had been up for a few days it began erroring and not recieving messages like it should.


ERR! markAsRead => error: 1357004,

ERR! markAsRead => errorSummary: 'Ett fel har inträffat.',

ERR! markAsRead => errorDescription: 'Försök med att stänga och sedan öppna webbläsarfönstret på nytt.',

ERR! markAsRead => payload: null,

ERR! markAsRead => bootloadable: {},

ERR! markAsRead => ixData: {},

ERR! markAsRead => gkxData: {},

ERR! markAsRead => lid:'648651918297341943'}

The error is the same for getUserInfo.

I use the bleeding edge version of the API.

For anyone trying to debug, the error messages are
"An error has occurred."
"Try closing and then re-open the browser window."

@LokeofAsgard I'm assuming that restarting the bot at this point fixed the problem for another few days?

@Schmavery yes. I added a try/catch around my sendMessage and if the errorcode is 1357004 I just reconnect

Ok, if it also happens in sendmessage, I guess it's probably not specific to markAsRead and getUserInfo.
This used to happen before we added a change to try update some cookies that were getting changed in a different way. Maybe there has been another similar change since then.

I too just saw this upon sending a message after being connected for several days. As a workaround in our application, I'm just going to have it reconnect every 8 hours and see if that resolves it.

Just for reference, I'm using the following code just after calling facebook-chat-api listen():

      if (this.restartTimer)
      {
        clearTimeout(this.restartTimer);
      }

      if (stop)
      {
        // Restart every 8 hours, give or take an hour
        var restartHours = 8 + Math.random();
        var restartMs = Math.floor(restartHours*60*60*1000);

        this.restartTimer = setTimeout(() => {
          console.log("Stopping and restarting to help prevent message send errors. ", restartHours.toFixed(2), "hours (", restartMs, " ms) have passed since the last auto-restart.");
          stop();
          this.login();
        }, restartMs);
      }

You will need to tweak this for your own application, here's a guide:
stop() in my app is the function returned by my app's facebook-chat-api listen() call. If yours is differently named, change it.
this.login() is my own app's function that calls facebook-chat-api login()

I've now noticed that my fix above doesn't seem to work properly. After 8 hours pass and my stop() / login() sequence happens above, things seem to be working fine for a bit (maybe an hour or so), but then I eventually end up with an error like this:

Unhandled rejection Error: ESOCKETTIMEDOUT
    at ClientRequest.<anonymous> (/home/vector/matrix-puppet-facebook/node_modules/request/request.js:812:19)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at ClientRequest.emit (events.js:208:7)
    at TLSSocket.emitTimeout (_http_client.js:706:34)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at TLSSocket.emit (events.js:208:7)
    at TLSSocket.Socket._onTimeout (net.js:410:8)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

I'm not sure why this is happening. Perhaps the old instance of facebook-chat-api has stuck around in some way. Is calling stop() and login again the proper way to "restart" the facebook-chat-api without restarting the process altogether?

I guess for now, I'll just switch to a workaround where I kill and restart the entire process, that seems the most reliable way.