Skip to content

Commit

Permalink
fix: close server stream on observer unsubscribe (#309)
Browse files Browse the repository at this point in the history
* close server stream on unsubscribe

* Fix lint error, use a lambda just in case.

Co-authored-by: Stephen Haberman <stephen.haberman@gmail.com>
  • Loading branch information
justinschuldt and stephenh committed Jun 13, 2021
1 parent 5cd3ef9 commit 4b72563
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion integration/grpc-web/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ export class GrpcWebImpl {
: metadata || this.options.metadata;
return new Observable((observer) => {
const upStream = () => {
grpc.invoke(methodDesc, {
const client = grpc.invoke(methodDesc, {
host: this.host,
request,
transport: this.options.streamingTransport || this.options.transport,
Expand All @@ -1009,6 +1009,7 @@ export class GrpcWebImpl {
}
},
});
observer.add(() => client.close());
};
upStream();
}).pipe(share());
Expand Down
3 changes: 2 additions & 1 deletion src/generate-grpc-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function createInvokeMethod() {
: metadata || this.options.metadata;
return new Observable(observer => {
const upStream = (() => {
${grpc}.invoke(methodDesc, {
const client = ${grpc}.invoke(methodDesc, {
host: this.host,
request,
transport: this.options.streamingTransport || this.options.transport,
Expand All @@ -317,6 +317,7 @@ function createInvokeMethod() {
}
},
});
observer.add(() => client.close());
});
upStream();
}).pipe(${share}());
Expand Down

0 comments on commit 4b72563

Please sign in to comment.