nameko / nameko-grpc

GRPC Extensions for Nameko
Apache License 2.0
59 stars 12 forks source link

Catch StopIteration and raise grpc error #46

Closed stephenc-pace closed 2 years ago

stephenc-pace commented 2 years ago

Summary

It's possible for a connection to terminate before a response has been returned. In this case, we end the stream iterator

    def consume(self, message_type):
        """Consume the data in this stream by yielding `message_type` messages,
        or raising if the stream was closed with an error.
        """
        while True:
            item = self.queue.get()
            if isinstance(item, GrpcError):
                raise item
            elif item is STREAM_END:
                break

If a stream is closed before a response is returned then the stream 'breaks', raising a StopIteration exception which we need to handle. We can't just check if it's closed as we want it to raise any errors.

Notes: