Skip to main content
Skip to Content
interlace
SecurityPlugin: grpc-securityRules

require-call-deadline

Give every gRPC client call a deadline

Next step

require-call-deadline ships in eslint-plugin-grpc-security, with 7 of its 8 rules in the recommended preset.

Install
npm install -D eslint-plugin-grpc-security
eslint.config.js
import { configs } from 'eslint-plugin-grpc-security';

export default [configs.recommended];

Plugin pagenpmSource on GitHub

Give every gRPC client call a deadline.

Why

A gRPC call has no timeout unless the caller sets a deadline. Against a slow or stalled server, every call without one holds its stream, its memory and whatever is waiting on it, indefinitely. Under load those pile up until the client runs out of resources, and a single slow dependency takes down everything that calls it.

Rule details

The rule identifies a client by structure: new X(target, credentials) whose second argument is gRPC channel credentials (credentials.createSsl(), createInsecure(), combineChannelCredentials(…)). The credentials can be inline or in a const, and X can be any generated service client or Client.

A method call on that client is reported when:

  • no argument is an options object with a deadline (inline or through a const), and
  • every argument the file can't read sits where only the request can go. An unreadable later argument might be an options object that holds a deadline, so the rule stays silent. The same goes for a single unreadable argument with no callback, which could be a streaming call's options.

close(), getChannel() and waitForReady() aren't calls and are skipped.

This rule is in strict only. A deadline can also be set by an interceptor or a wrapper the file can't see, so a missing deadline is a best practice the code doesn't prove, not a defect.

Incorrect

const client = new pkg.Orders(target, grpc.credentials.createSsl());
client.GetOrder({ id }, (err, order) => {});

Correct

const client = new pkg.Orders(target, grpc.credentials.createSsl());
client.GetOrder({ id }, { deadline: Date.now() + 5000 }, (err, order) => {});

Further reading

Use this rule

npm install -D eslint-plugin-grpc-security
eslint.config.js
import grpcSecurity from 'eslint-plugin-grpc-security';export default [  {    plugins: { 'grpc-security': grpcSecurity },    rules: {      'grpc-security/require-call-deadline': 'error'    },  },];
npm install -D oxlint-plugin-grpc-security
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-grpc-security"],  "rules": {    "grpc-security/require-call-deadline": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-grpc-security'],    rules: {      'grpc-security/require-call-deadline': 'error',    },  },});

oxlint-plugin-grpc-security re-exports eslint-plugin-grpc-security/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.