smnbbrv / ngx-grpc

Angular gRPC framework
MIT License
238 stars 34 forks source link

do I need to handle connection close in server side #93

Closed gkyildirim closed 1 year ago

gkyildirim commented 1 year ago

I apologize if this is off the topic. If it is please feel free to close/ignore it.

As I understand I can close a server stream from client side by just unsubscribing like this.

setTimeout(() => {
            sub.unsubscribe();
        }, 5000);

My server is written in golang. And server sends stream even if unsubscription succesfully happened in angular.

May I ask if it should not be or do I have to figure out a way to handle connection close in the golang side?

Thanks in advance.

smnbbrv commented 1 year ago

Hi,

normally yep, unsubscribing should lead to a request cancellation.

Could you check in your browser's "Network" devtools section whether request is cancelled?

If not, this could be issue of the library.

If yes then the source of the issue could be either in a proxy: "standard" from envoy or one from improbable (even if you embed improbable proxy as a lib directly into your golang application).

It's also important what transport you use. If you use websocket transport from improbable, it could be a problem of the transport itself (at least I faced some issues with websocket transport).

So, as you might see, there are really many places where it could go wrong.

gkyildirim commented 1 year ago

Thanks for your through answer. And sorry for the long delay. I was away for some time.

I see no request cancellation either in chrome's network tool nor in golang net/http request logs.

I embed improbable proxy as a lib and I do not use websocket.

gkyildirim commented 1 year ago

It seems that I was wrong. Cancellation is send but it was not easy to detect for me. I even tried with Fiddler but could not figure out. There was a more than one obstacles for me. First I use angular proxy for my backend access and stream cancellation is not send with it. I tried to figure out if there is a working config but I could not. Second was the net/http. This is not certainly my area of expertise and I just switch to h2c handler and cancellation happened (even saw it in the http log which I could not before). At short stream cancellation works but I have not enought time to figure out the exact cause to write down here but some clues. @smnbbrv sorry for the noise and thanks for this great project.

smnbbrv commented 1 year ago

No problem, I'm glad you solved the issue :)