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.
nice-grpc-client-middleware-retry
Advanced tools
Client middleware for nice-grpc that adds automatic retries to unary calls. Exponential backoff is added between retry attempts.
npm install nice-grpc-client-middleware-retry
It is generally not safe to retry calls in case of errors, because the failed call might have reached the server and had an effect on the system. For example, an increment operation is not idempotent, since executing it twice will increment by 2. In contrast, a delete operation can be made idempotent, if the server ignores the delete of an already non-existent entity. Any read-only operation is inherently idempotent .
In this middleware, the retries are disabled by default, unless the method is marked as idempotent:
service ExampleService {
rpc ExampleMethod(ExampleMethodRequest) returns (ExampleMethodResponse) {
option idempotency_level = IDEMPOTENT;
}
}
Note that method options currently work only when compiling with
ts-proto
.
import {
createClientFactory,
createChannel,
ClientError,
Status,
} from 'nice-grpc';
import {retryMiddleware} from 'nice-grpc-client-middleware-retry';
const clientFactory = createClientFactory().use(retryMiddleware);
const channel = createChannel(address);
const client = clientFactory.create(ExampleService, channel);
const response = await client.exampleMethod(request, {
// not needed if the method is marked as idempotent in Protobuf
retry: true,
// defaults to 1
retryMaxAttempts: 5,
// defaults to [UNKNOWN, RESOURCE_EXHAUSTED, INTERNAL, UNAVAILABLE]
retryableStatuses: [Status.UNAVAILABLE],
onRetryableError(error: ClientError, attempt: number, delayMs: number) {
logger.error(error, `Call failed (${attempt}), retrying in ${delayMs}ms`);
},
});
You can also set retryMaxAttempts
to Infinity
and use AbortSignal
to
cancel
the retried call:
import AbortController from 'node-abort-controller';
const abortController = new AbortController();
setTimeout(() => {
abortController.abort();
}, 1000);
const response = await client.exampleMethod(request, {
retry: true,
retryMaxAttempts: Infinity,
signal: abortController.signal,
});
When using this middleware together with deadline middleware, make sure to have them in correct order. This way, if the retry is currently in a backoff delay, it will be correctly aborted upon deadline:
const clientFactory = createClientFactory()
.use(retryMiddleware)
.use(deadlineMiddleware);
Instead of specifying retry options per call, you can configure retries when creating the client:
const clientFactory = createClientFactory().use(retryMiddleware);
const channel = createChannel(address);
const client = clientFactory.create(ExampleService, channel, {
// set defaults for all methods
'*': {
retryMaxAttempts: 5,
},
// enable retries for particular method
exampleMethod: {
retry: true,
},
});
FAQs
Retry client middleware for nice-grpc
The npm package nice-grpc-client-middleware-retry receives a total of 43,688 weekly downloads. As such, nice-grpc-client-middleware-retry popularity was classified as popular.
We found that nice-grpc-client-middleware-retry demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.