Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Suggest adding a ECONNABORTED retry #25

Description

@garygchai

The superagent lib will abort the request before retry, and the error code will be ECONNABORTED. So I suggest that add a retry at the retries.js. This error code was added at the superagent source code. https://github.com/visionmedia/superagent/blob/master/lib/should-retry.js

/**
 * Request be aborted
 */
function econnabort (err, res) {
  return err && err.code === 'ECONNABORTED';
}

In addition, if ECONNABORTED is added, one issue should be attention.

Some code like following:

request.get('xxxx')
	   .timeout(5000)
	   .retry(2)
	   .end((err, res) => {
	   		// TODO
	   })

when first time the request is aborted, the this._aborted will be true, and next time retry request, the request will be return. Show the code.

// https://github.com/visionmedia/superagent/blob/master/lib/request-base.js
RequestBase.prototype._timeoutError = function(reason, timeout, errno){
  if (this._aborted) { // The second time here is true.
    return;
  }
  var err = new Error(reason + timeout + 'ms exceeded');
  err.timeout = timeout;
  err.code = 'ECONNABORTED';
  err.errno = errno;
  this.timedout = true;
  this.abort();
  this.callback(err);
};

So we can fix it at reset function.

// https://github.com/segmentio/superagent-retry/blob/master/lib/index.js
/**
 * HACK: Resets the internal state of a request.
 */

function reset (request, timeout) {
  var headers = request.req._headers;
  var path = request.req.path;

  request.req.abort();
  request.called = false;
  request._aborted = false; // code is here
  request.timeout(timeout);
  delete request.req;
  delete request._timer;
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions