Skip to content

GRPC client error: connection closed before server preface received #3109

@icexin

Description

@icexin

Describe the bug
When using a GRPC client to call a brpc server with redis protocol enabled, the client will failed with code = Unavailable desc = connection closed before server preface received.

Introduced by #3024 , the Redis protocol check is too loose, and it parses the GRPC protocol as the Redis protocol.

To Reproduce

This is the code to reproduce the the issue.

#include <brpc/server.h>

class RedisService : public brpc::RedisService {
};

int main(int argc, char* argv[]) {
    google::ParseCommandLineFlags(&argc, &argv, true);
    brpc::Server server;
    brpc::ServerOptions options;
    RedisService redis_service;
    options.redis_service = &redis_service;
    if (server.Start(7447, &options) != 0) {
        LOG(ERROR) << "Failed to start dummy server";
        return 1;
    }
    server.RunUntilAskedToQuit();
    return 0;
}

Expected behavior

The GRPC client failed with `code = Unimplemented desc = [10.234.44.157:4003][E1002]Fail to find method on /service.method"

Versions
OS: ubuntu 20.04 kernel: 5.15.0
Compiler: clang-12
brpc: 1.14.1
protobuf: 27.3

Additional context/screenshots

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugthe code does not work as expected

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions