最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

grpc - Error "INTERNAL: Encountered end-of-stream mid-frame" while running an application with Concurrent Thre

programmeradmin1浏览0评论

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.");
    }
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论