Are calls to StreamObserver serialized?

40 views
Skip to first unread message

enat...@gmail.com

unread,
Apr 29, 2020, 5:44:50 PM4/29/20
to grpc.io
Is it the case that (in the Java bindings), the gRPC framework will serialize invocations to the StreamObserver used to process incoming client requests (e.g., onNext, onError, onCompleted)? I.e. they will never be invoked concurrently.

I looked around before I asked but couldn't find the answer.

Would appreciate any help!

Christoph John

unread,
Apr 29, 2020, 6:05:27 PM4/29/20
to enat...@gmail.com, grpc.io
No, they are not serialized. You need to do that by yourself. Otherwise you might encounter strange behaviour. I opened an issue once because I stumbled upon the same problem: https://github.com/grpc/grpc-java/issues/6323
Also see https://github.com/grpc/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java#L32

Cheers,
Chris.
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/1024fc7e-678f-45fd-a2ba-29cb3c118fff%40googlegroups.com.

Message has been deleted

enat...@gmail.com

unread,
Apr 29, 2020, 6:21:26 PM4/29/20
to grpc.io
Interesting - thank you very much! I did see this in the StreamObserver doc:

"Since individual StreamObservers are not thread-safe, if multiple threads will be writing to a StreamObserver concurrently, the application must synchronize calls"

Based on that, since it is a StreamObserver, I figured that the gRPC framework must also be abiding by this contract. Good to know otherwise, maybe I misunderstood the above doc.

Thanks again.

On Wednesday, April 29, 2020 at 5:05:27 PM UTC-5, Christoph John wrote:
No, they are not serialized. You need to do that by yourself. Otherwise you might encounter strange behaviour. I opened an issue once because I stumbled upon the same problem: https://github.com/grpc/grpc-java/issues/6323
Also see https://github.com/grpc/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java#L32

Cheers,
Chris.

On 29.04.20 23:44, enat...@gmail.com wrote:
Is it the case that (in the Java bindings), the gRPC framework will serialize invocations to the StreamObserver used to process incoming client requests (e.g., onNext, onError, onCompleted)? I.e. they will never be invoked concurrently.

I looked around before I asked but couldn't find the answer.

Would appreciate any help!
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grp...@googlegroups.com.

Eric Anderson

unread,
May 4, 2020, 12:19:31 PM5/4/20
to enat...@gmail.com, grpc.io
On Wed, Apr 29, 2020 at 3:21 PM <enat...@gmail.com> wrote:
Interesting - thank you very much! I did see this in the StreamObserver doc:

"Since individual StreamObservers are not thread-safe, if multiple threads will be writing to a StreamObserver concurrently, the application must synchronize calls"

That documentation is correct, and gRPC framework abides by it as well. StreamObservers are not-thread-safe so the caller has to synchronize, if necessary.

It seems like Christoph was describing calling into a StreamObserver. And yes, he is correct, if you call into a StreamObserver from multiple threads, you must synchronize them yourself. But it sounded like you were talking being called, in which case you don't need to manage synchronization.

Christoph John

unread,
May 4, 2020, 3:45:23 PM5/4/20
to Eric Anderson, enat...@gmail.com, grpc.io
Eric, I think you are right and I misunderstood the original question. Sorry for that!

Cheers,
Chris.
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oP6TD79r_0dUEjk1DeqZ-n9SHtQoW0eJwKFPfAwr%2BuMYQ%40mail.gmail.com.

enat...@gmail.com

unread,
May 4, 2020, 4:50:41 PM5/4/20
to grpc.io
Thank you for clarifying!
Reply all
Reply to author
Forward
0 new messages