Skip to content

Commit 0c151d8

Browse files
Fix gRPC stream observer leak on ProcessBundleHandler shutdown (#39390)
* Fix gRPC stream observer leak on ProcessBundleHandler shutdown * tears down active gRPC multiplexers on ProcessBundleHandler shutdown * Update sdks/java/harness/src/main/java/org/apache/beam/fn/harness/data/BeamFnDataGrpcClient.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 9baa19a commit 0c151d8

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

sdks/java/harness/src/main/java/org/apache/beam/fn/harness/control/ProcessBundleHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ public BeamFnApi.InstructionResponse.Builder trySplit(InstructionRequest request
767767
/** Shutdown the bundles, running the tearDown() functions. */
768768
public void shutdown() throws Exception {
769769
bundleProcessorCache.shutdown();
770+
beamFnDataClient.close();
770771
}
771772

772773
@VisibleForTesting

sdks/java/harness/src/main/java/org/apache/beam/fn/harness/data/BeamFnDataClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.beam.fn.harness.data;
1919

20+
import java.io.Closeable;
21+
import java.io.IOException;
2022
import java.util.List;
2123
import org.apache.beam.model.fnexecution.v1.BeamFnApi.Elements;
2224
import org.apache.beam.model.pipeline.v1.Endpoints;
@@ -30,7 +32,7 @@
3032
* provide a receiver of outbound elements. Callers can register themselves as receivers for inbound
3133
* elements or can get a handle for a receiver of outbound elements.
3234
*/
33-
public interface BeamFnDataClient {
35+
public interface BeamFnDataClient extends Closeable {
3436
/**
3537
* Registers a receiver for the provided instruction id.
3638
*
@@ -72,4 +74,9 @@ void unregisterReceiver(
7274
/** Get the outbound observer for the specified apiServiceDescriptor and dataStreamId. */
7375
StreamObserver<Elements> getOutboundObserver(
7476
Endpoints.ApiServiceDescriptor apiServiceDescriptor, String dataStreamId);
77+
78+
@Override
79+
default void close() throws IOException {
80+
// Default to no-op
81+
}
7582
}

sdks/java/harness/src/main/java/org/apache/beam/fn/harness/data/BeamFnDataGrpcClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ public void poisonInstructionId(String instructionId) {
118118
}
119119
}
120120

121+
@Override
122+
public void close() {
123+
for (BeamFnDataGrpcMultiplexer client : multiplexerCache.values()) {
124+
try {
125+
client.close();
126+
} catch (Exception e) {
127+
LOG.warn("Failed to close multiplexer", e);
128+
}
129+
}
130+
multiplexerCache.clear();
131+
}
132+
121133
@Override
122134
public StreamObserver<Elements> getOutboundObserver(
123135
ApiServiceDescriptor apiServiceDescriptor, String dataStreamId) {

0 commit comments

Comments
 (0)