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

gRPC library is not deinitialized after stream read operations #31045

Closed
nikola-sh opened this issue Sep 18, 2022 · 4 comments
Closed

gRPC library is not deinitialized after stream read operations #31045

nikola-sh opened this issue Sep 18, 2022 · 4 comments

Comments

@nikola-sh
Copy link

What version of gRPC and what language are you using?

9d047f8
C++

What operating system (Linux, Windows,...) and version?

Windows 10
Linux

What runtime / compiler are you using (e.g. python version or version of gcc)

VS 2022
gcc 11.2.0

What did you do?

I noticed that my gRPC client application crashes sometimes after main.
It was happened because gRPC doesn't deinitialize itself after stream operations even if all gRPC objects are destroyed.
To reproduce this situation I added to the helloworld sample async streaming operations and gRPC deinitialization waiting at the end.
nikola-sh@3c7d8bc

If we run the server that sends 1 message and client

> greeter_async_server.exe 1
> greeter_async_client2.exe

client reads message and is waiting in while (grpc_is_initialized()) forever

started
ok: Hello 123
!ok
Waiting GRPC shutdown
Waiting GRPC shutdown
Waiting GRPC shutdown
Waiting GRPC shutdown
...

But if you run server that sends 0 message all will be fine.

> greeter_async_server.exe 0
> greeter_async_client2.exe

client output:

started
!ok

In case of 10 messages problem reproduction is unstable, sometimes we see Waiting GRPC shutdown, but sometimes not.

What did you expect to see?

I know that gRPC deinitialization can be asynchronous but I expect that waiting while (grpc_is_initialized()) is finite and ends fast.

@yashykt
Copy link
Member

yashykt commented Sep 20, 2022

grpc_is_initialized is not part of the public API for gRPC C++. It is a gRPC Core API which is only meant to be used internally by the gRPC wrapped languages. At this point, it is considered something akin to an implementation detail.

@yashykt
Copy link
Member

yashykt commented Sep 20, 2022

The user of a C++ library should not need to care whether gRPC Core is initialized or not.

@yashykt yashykt closed this as completed Sep 20, 2022
@nikola-sh
Copy link
Author

@yashykt , grpc_is_initialized was used only to highlight the problem.
The problem is

I noticed that my gRPC client application crashes sometimes after main.
It was happened because gRPC doesn't deinitialize itself after stream operations even if all gRPC objects are destroyed.

C/C++ runtime deinitializes itself after main and alive GRPC threads crash.

@nikola-sh
Copy link
Author

The problem is fixed in v1.51.0.
Probably by #30992

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants