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

conn is null #10

Open
mattn opened this issue Jun 24, 2022 · 9 comments
Open

conn is null #10

mattn opened this issue Jun 24, 2022 · 9 comments

Comments

@mattn
Copy link
Contributor

mattn commented Jun 24, 2022

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 }
@shinshin86
Copy link

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.

@mattn
Copy link
Contributor Author

mattn commented Jun 24, 2022

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

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

@shinshin86
Copy link

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!

@prohazko2
Copy link
Owner

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.

@shinshin86
Copy link

Thanks for the comment. Sounds good!

@mattn
Copy link
Contributor Author

mattn commented Jun 26, 2022

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)
	}
}

@prohazko2
Copy link
Owner

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

@prohazko2
Copy link
Owner

prohazko2 commented Aug 17, 2022

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
Copy link
Owner

prohazko2 commented Aug 17, 2022

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

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

3 participants