Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
apollo-link-retry
Advanced tools
Sometimes, you're in an unreliable situation but you would rather wait longer than explicitly fail an operation. apollo-link-retry
provides exponential backoff, and jitters delays between attempts by default. It does not (currently) handle retries for GraphQL errors in the response, only for network errors.
One such use case is to hold on to a request while a network connection is offline and retry until it comes back online.
import { RetryLink } from "apollo-link-retry";
const link = new RetryLink();
The standard retry strategy provides exponential backoff with jittering, and takes the following options, grouped into delay
and attempt
strategies:
delay.initial
: The number of milliseconds to wait before attempting the first retry.
delay.max
: The maximum number of milliseconds that the link should wait for any retry.
delay.jitter
: Whether delays between attempts should be randomized.
attempts.max
: The max number of times to try a single operation before giving up.
attempts.retryIf
: A predicate function that can determine whether a particular response should be retried.
The default configuration is equivalent to:
new RetryLink({
delay: {
initial: 300,
max: Infinity,
jitter: true
},
attempts: {
max: 5,
retryIf: (error, _operation) => !!error
}
});
Starting with initialDelay
, the delay of each subsequent retry is increased exponentially, meaning it's multiplied by 2 each time. For example, if initialDelay
is 100, additional retries will occur after delays of 200, 400, 800, etc.
With the jitter
option enabled, delays are randomized anywhere between 0ms (instant), and 2x the configured delay. This way you get the same result on average, but with random delays.
These two features combined help alleviate the thundering herd problem, by distributing load during major outages. Without these strategies, when your server comes back up it will be hit by all of your clients at once, possibly causing it to go down again.
Instead of the options object, you may pass a function for delay
and/or attempts
, which implement custom strategies for each. In both cases the function is given the same arguments (count
, operation
, error
).
The attempts
function should return a boolean indicating whether the response should be retried. If yes, the delay
function is then called, and should return the number of milliseconds to delay by.
import { RetryLink } from "apollo-link-retry";
const link = new RetryLink({
attempts: (count, operation, error) => {
return !!error && operation.operationName != 'specialCase';
},
delay: (count, operation, error) => {
return count * 1000 * Math.random();
},
});
FAQs
Retry Apollo Link for GraphQL Network Stack
The npm package apollo-link-retry receives a total of 63,517 weekly downloads. As such, apollo-link-retry popularity was classified as popular.
We found that apollo-link-retry demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.