这个问题通常是因为你的程序没有正确地关闭ManagedChannel导致的。可以尝试在你的代码中关闭ManagedChannel或在BeamOptions中设置一个ShutdownHook。以下是示例代码:
//在管道中设置一个ShutdownHook
public class MyOptions extends PipelineOptions {
@Description("MyOption")
@Default.String("myValue")
String getMyOption();
void setMyOption(String value);
@Description("Set shutdown hook")
@Default.Boolean(true)
Boolean getSetShutdownHook();
void setSetShutdownHook(Boolean value);
}
MyOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(MyOptions.class);
if (options.getSetShutdownHook()) {
//在程序关闭时自动关闭ManagedChannel
LifecycleManager.addShutdownHook(() -> {
try {
grpcCleanup.run(); //关闭gRPC channel和executor
} catch (Exception e) {
// log exception
}
});
}
// 在代码中主动关闭ManagedChannel
ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port).build();
try {
// do something with channel
} finally {
channel.shutdown();
}