Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'state') #2347

Closed
Fonger opened this issue Feb 7, 2023 · 2 comments
Closed

TypeError: Cannot read properties of undefined (reading 'state') #2347

Fonger opened this issue Feb 7, 2023 · 2 comments

Comments

@Fonger
Copy link

Fonger commented Feb 7, 2023

Problem description

After we upgrade @grpc/grpc-js from 1.7.3 to 1.8.7, we start to see server crash frequently with this error:

TypeError: Cannot read properties of undefined (reading 'state')
    at RetryingCall.sendMessageWithContext (/workspace/node_modules/@grpc/grpc-js/build/src/retrying-call.js:542:22)
    at /workspace/node_modules/@grpc/grpc-js/build/src/resolving-call.js:106:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This map to this line 597 call.state === 'ACTIVE'

} else {
this.commitCallWithMostMessages();
const call = this.underlyingCalls[this.committedCallIndex!];
bufferEntry.callback = context.callback;
if (call.state === 'ACTIVE' && call.nextMessageToSend === messageIndex) {
call.call.sendMessageWithContext({

Reproduction steps

Sorry I can't give a precise step to reproduce for now, however maybe it's possible to find the issue by code review?

I suspect it's because this.commitedCallIndex is -1 because this.underlyingCalls is an empty array.

let mostMessages = -1;
let callWithMostMessages = -1;
for (const [index, childCall] of this.underlyingCalls.entries()) {
if (childCall.nextMessageToSend > mostMessages) {
mostMessages = childCall.nextMessageToSend;
callWithMostMessages = index;
}
}
this.commitCall(callWithMostMessages);

Or committedCallIndex is null because this.state is COMMITED or COMPLETED but we force nullish! here.

const call = this.underlyingCalls[this.committedCallIndex!];

Or one of element of underlyingCalls maybe undefined so we should use optional chaining like this one here: (I think this one is unlikely)

if (call?.state === 'ACTIVE' && call.nextMessageToSend === halfCloseIndex) {

The only dependency we use @grpc/grpc-js is opentelemetry @opentelemetry/exporter-trace-otlp-grpc 0.34.0.

Environment

  • OS name, version and architecture: Alpine Linux v3.17
  • Node version: v18.14.0
  • Node installation method: docker node:18-alpine
  • If applicable, compiler version:
  • Package name and version: @grpc/grpc-js@1.8.7

Additional context

@murgatroid99
Copy link
Member

I think I fixed the issue in version 1.8.8. Please update and try it out.

@Fonger
Copy link
Author

Fonger commented Feb 9, 2023

I think I fixed the issue in version 1.8.8. Please update and try it out.

Thanks! I can confirm this is fixed in 1.8.8.

@Fonger Fonger closed this as completed Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants