I am working on a multithreaded application where I create a few threads. One of the threads makes a gRPC call, and midway through the frame, the thread encounters an END_OF_STREAM error while reading the response. The other threads performs some other work, and may interact with same/another gRPC call.
I am curious to know in what scenarios END_OF_STREAM error might occur in this context? A sample example mimicking my production scenario is given for reference.
import io.grpc.*;
import java.util.concurrent.*;
public class Main {
static class MockGrpcClient {
public String grpcStub.invokeService1() {
}
public String grpcStub.invokeService2() {
}
}
static class Thread1 extends Thread {
private final MockGrpcClient grpcClient;
public Thread1(MockGrpcClient grpcClient) {
this.grpcClient = grpcClient;
}
@Override
public void run() {
try {
grpcClient.invokeService1();
} catch (StatusRuntimeException e) {
System.out.println("Thread " + Thread.currentThread().getName() + " encountered an error: " + e.getMessage());
}
}
}
// Thread 2: Simulates a different task
static class Thread2 extends Thread {
@Override
public void run() {
try {
grpcClient.invokeService2();
} catch (StatusRuntimeException e) {
System.out.println("Thread " + Thread.currentThread().getName() + " encountered an error: " + e.getMessage());
}
}
}
public static void main(String[] args) throws InterruptedException {
MockGrpcClient grpcClient = new MockGrpcClient();
// Create and start the threads
Thread1 thread1 = new Thread1(grpcClient);
Thread2 thread2 = new Thread2();
thread1.start();
thread2.start();
thread1.join();
thread2.join();
//Getting INTERNAL: Encountered end-of-stream mid-frame after sometime
System.out.println("Main thread completed.");
}
}