deno-grpc icon indicating copy to clipboard operation
deno-grpc copied to clipboard

conn is null

Open mattn opened this issue 2 years ago • 9 comments

Hi, I'm trying to use this on Windows. client.ts on README.md works good with SayHello but ShoutHello does not.

HelloReply { message: "hello unary #1" }
HelloReply { message: "hello unary #2" }
HelloReply { message: "hello streamed #0" }
HelloReply { message: "hello streamed #1" }
HelloReply { message: "hello streamed #2" }
errrrrrr TypeError: Cannot read properties of null (reading 'write')
    at GrpcClientImpl.sendFrame (https://deno.land/x/[email protected]/client.ts:189:25)
    at GrpcClientImpl.flush (https://deno.land/x/[email protected]/client.ts:172:18)
{ type: "WINDOW_UPDATE", flags: {}, stream: 0, window_size: 72 }
errrrrrr TypeError: Cannot read properties of null (reading 'write')
    at GrpcClientImpl.sendFrame (https://deno.land/x/[email protected]/client.ts:189:25)
    at GrpcClientImpl.flush (https://deno.land/x/[email protected]/client.ts:172:18)
{ type: "WINDOW_UPDATE", flags: {}, stream: 0, window_size: 72 }

mattn avatar Jun 24 '22 01:06 mattn

I also encountered the same error.

# My deno environment
$ deno --version
deno 1.23.0 (release, aarch64-apple-darwin)
v8 10.4.132.5
typescript 4.7.2

I debugged it and found that rewriting the code like this eliminated the error, but this is not a fundamental solution. I also encounter the same error again as I rewrite the code to execute.

diff --git a/client.ts b/client.ts
index 4a13ce2..f802ae5 100644
--- a/client.ts
+++ b/client.ts
@@ -166,7 +166,7 @@ export class GrpcClientImpl implements GrpcClient {

     while (this.frames.length) {
       const f = this.frames.shift();
-      if (!f) {
+      if (f.type === "WINDOW_UPDATE" && f.window_size % 24 === 0) {
         break;
       }
       await this.sendFrame(f);

I have not been able to get to the specific solution as I still do not understand the relevant processes in the project. But I hope this information will help you to solve the problem.

shinshin86 avatar Jun 24 '22 12:06 shinshin86

Thank you. still f is possibly be null. Is this better?

const f = this.frames.shift!();

mattn avatar Jun 24 '22 13:06 mattn

Wow, cool! I didn't know it could be expressed that way so I thought that was interesting. You are right, there is a possibility that f could be null. Thanks!

shinshin86 avatar Jun 25 '22 08:06 shinshin86

Hi, I also have same problem.
It's because client.close() at the end of example causes connection termination, and client wants to write some frames (WINDOW_UPDATE) to closed connection. I tnink I'll fix this by skip any writes on terminated client.

prohazko2 avatar Jun 25 '22 13:06 prohazko2

Thanks for the comment. Sounds good!

shinshin86 avatar Jun 26 '22 04:06 shinshin86

I know another issue that occur errors when client is closed. Will it be fixed by the change? I implemented Go client generated from greeter.proto by protoc.

image

image

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/mattn/grpc-deno-go/greeter"
	"google.golang.org/grpc"
)

func main() {
	conn, err := grpc.Dial("127.0.0.1:15070", grpc.WithInsecure())
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	client := greeter.NewGreeterClient(conn)

	req := greeter.HelloRequest{Name: "mattn"}
	reply, err := client.SayHello(context.Background(), &req)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(reply)

	stream, err := client.ShoutHello(context.Background(), &req)
	defer stream.CloseSend()

	for {
		reply, err := stream.Recv()
		if err != nil {
			break
		}
		fmt.Println(reply)
	}
}

mattn avatar Jun 26 '22 05:06 mattn

@mattn I think It's different case, but I'll check this also

prohazko2 avatar Jun 28 '22 13:06 prohazko2

Sorry for long response.

Most of these errors caused by excesive console logging during development stage.

Fixed (actually muted) them at https://github.com/prohazko2/deno-grpc/tree/0.4.6

prohazko2 avatar Aug 17 '22 00:08 prohazko2

Also, if You are planning to use gPRC on Deno - consider tracking https://github.com/denoland/deno/issues/3326 issue from Deno team, because this project (deno-grpc) is not actively maintained right now

prohazko2 avatar Aug 17 '22 00:08 prohazko2