Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
A simple module to be used for creating exponentially weighted backoff attempts. Originally extracted from Primus.
NOTICE
If you were a pre-1.0.0 back
user, the API has changed to what is found below.
If you do not like this slightly different abstraction and would prefer the
former, slightly simpler API, it is still available with require('back/reconnect')
.
The API change thanks to a contribution from @Raynos makes things simpler as you don't have to manage the copying of the options object yourself in order to handle repeated backoff cases.
var http = require('http');
var back = require('back');
//
// Options to use for backoff
//
// Remark: This object is modified so it should be cloned if you are dealing
// with independent backoff attempts and want to use these values as a base.
//
var options = {
retries: 3,
minDelay: 1000, // Defaults to 500ms
maxDelay: 10000, // Defaults to infinity
// The following option is shown with its default value but you will most
// likely never define it as it creates the exponential curve.
factor: 2,
};
// Where we will store the backoff instance during a particular backoff attempt
var attempt;
function retry(err) {
var back = attempt || (attempt = new Back(options));
return back.backoff(function (fail) {
if (fail) {
// Oh noez we never reconnect :(
console.error('Retry failed with ' + err.message);
process.exit(1);
}
//
// Remark: .attempt and .timeout are added to this object internally
//
console.log('Retry attempt # ' + back.settings.attempt +
' being made after ' + back.settings.timeout + 'ms');
request();
});
}
function request() {
http.get('http://localhost:9000', function (res) {
console.log('Successful Response that will not happen!');
//
// If we succeeded, we would set the current to null so the next error
// generates a new instance.
//
attempt = null;
}).on('error', retry);
}
request();
var back = new Back(backoffOpts);
The Back
constructor function takes your backoff options and saves them as
settings
in the internal state of the back
object.
back.backoff(callback)
The back
instance has a backoff
method that takes a callback
that is
executed after a setTimeout
. The timeout is what is based on an exponential
backoff of course!
It will repeatedly all this callback based on the backoff options you passed to
the back instance until it exhausts its efforts. When it has exhausted its
attempts, it will return an error as the first argument to the callback.
back.close()
Clear backoff timer in cases where you want to dispose of the instance before the callback
is executed.
FAQs
Simple exponential backoff pulled out of Primus by @3rd-Eden
The npm package back receives a total of 10,427 weekly downloads. As such, back popularity was classified as popular.
We found that back demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.