rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar

Home Page:https://docs.rollbar.com/docs/javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XMLHttpRequest timeout issue

albertdaurell opened this issue · comments

Hi, I was recently trying to throttle the browser network and I found that rollbar is not handling timeouts because xmlhttprequest.timeout is not set, so this xdomainrequest.ontimeout or another timeout callback is never called.

xdomainrequest.ontimeout = function() { // Never thrown
  var msg = 'Request timed out';
  var code = 'ETIMEDOUT';
  callback(_newRetriableError(msg, code));
};

From XMLHttpRequest.timeout we can read: The default value is 0, which means there is no timeout

From some embedded devices this can be a problem because it seems the implementation from the device itself can have issues reporting if the network had some temporary issues, requests gets "stalled" and it never sends the data to rollbar.

Proposal

Adding some extra parameter in the main configuration:

var rollbarConfig = {
      maxRetries: 3,
      retryInterval: 10000,
      timeout: 5000,
      ...
    };

And setting this timeout after request.open(method, url, true);

I left an example there:

#947

Testing

Without the changes

  1. Open the browser
  2. Load rollbar
  3. Throttle the network to 1kb/s
  4. Call Rollbar.log
  5. Wait for 10 seconds
  6. Data is not sent

With my proposal

  1. Open the browser
  2. Load rollbar with config.timeout = 5000 and config.retryInterval = 10000
  3. Throttle the network to 1kb/s
  4. Call Rollbar.log
  5. See that timeout is reached and retry after 10 seconds is "executed"

Any update on this?

@albertdaurell Yes it would be good to support this. I'll take a closer look at the PR today.

@waltjones Also I'm thinking about adding maxRetries parameter, something like this:

Do you think better another pull? Or same? I would prefer both changes together, but... up to you...

@albertdaurell Good either way. If you prefer both together, that's OK.

Thx @waltjones added maxRetries also to the pull

@waltjones Should the issue also be closed?

BTW: Thank you very much for your support and patience!

Yes, this will be released in v2.22.0 tomorrow. Nice work, and thank you!