Right now pulled the code from g...@github.com:grpc/grpc.git.
Problem still exists - server aborts when client craches due to Ctrl+C or other reason.
The status code returned from grpc_call_start_batch() in Server::PerformOpsOnCall() is 5 (GRPC_CALL_ERROR_ALREADY_INVOKED).
Loks like grpc engine does not detect that client disapears and keeps previous call in queue for infinite time.
But in most of real-life cases the engine could detect that clients disapears - via ICMP, Keep-Alive, some kind of timeout on worst case....
The sample code to
reproduce the problem:
/////////////////
// test.proto
syntax = "proto3";
package tester;
service Test {
rpc ReadEvents (ReadEventsRequest) returns (stream TestEvent) {}
}
message ReadEventsRequest {
}
message TestEvent {
string event_name = 1;
}
///////////////////////////
// client.cc
int main()
{
grpc_init();
TestEvent e;
ClientContext context;
unique_ptr<Test::Stub> tester(
Test::NewStub(CreateChannel("localhost:7000", InsecureCredentials(), ChannelArguments())));
unique_ptr<ClientReader<TestEvent>> rd =
tester->ReadEvents(&context, ReadEventsRequest());
printf("begin read\n");
while ( rd->Read(&e) ) {
printf("event: %s\n", e.event_name().c_str());
}
printf("end read\n");
rd->Finish();
grpc_shutdown();
return 0;
}
///////////////////////
// server.cc
class TestService
: public Test::Service
{
unique_ptr<Server> server_;
public:
TestService(const string & address) {
ServerBuilder builder;
builder.AddPort(address, InsecureServerCredentials());
builder.RegisterService(this);
server_ = builder.BuildAndStart();
}
void run() {
server_->Wait();
}
private:
Status ReadEvents(ServerContext* context, const ReadEventsRequest* request, ServerWriter< TestEvent>* writer)
{
TestEvent e;
char line[256];
(void)(context); // unused
(void)(request); // unused
while ( fgets(line, sizeof(line) - 1, stdin) && strncmp(line, "quit", 4) != 0 ) {
e.set_event_name(line);
if ( !writer->Write(e) ) {
fprintf(stderr,"leave\n");
break;
}
}
return Status::OK;
}
};
int main()
{
grpc_init();
TestService service("localhost:7000");
service.run();
grpc_shutdown();
return 0;
}
вторник, 10 марта 2015 г., 21:37:15 UTC+2 пользователь Vijay Pai написал: