file:// naming service takes a comment after the address as the tag

Đang mở
#3,733 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@0z5a đang làm issue này rồi.

Từ ngày 11/11/2026.

  • #3735 của @0z5a — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start with SplitIntoServerAndTag() in src/brpc/policy/file_naming_service.cpp and the related unit test mentioned in the issue. Check how comment parsing handles lines with no tag, then verify that comments are ignored and the server tag is empty. An open pull request, #3735, already contains a fix for this issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

In a file:// naming service file, a line with an address and a comment but no tag gets the comment as its tag:

10.24.234.18:8080  # a comment without tag

gives a ServerNode with tag # a comment without tag. docs/en/client.md says "contents after # are comments and ignored", and a comment after a tag (10.24.234.17:8080 tag1 # a comment) is cut correctly.

Because a server is identified by address + tag, the same address with two different comments becomes two instances. The comment is also what NamingServiceFilter and the tag-aware load balancers see.

The cause is in SplitIntoServerAndTag() (src/brpc/policy/file_naming_service.cpp:49-53 at 05abb1c3): the first character after the blanks is taken as the first tag character, and the search for # starts at the next one. list:// and remote file lists use the same function.

To Reproduce

#include <stdio.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "butil/endpoint.h"
#include "butil/files/temp_file.h"
#include "brpc/channel.h"
#include "brpc/naming_service_filter.h"

class RecordingFilter : public brpc::NamingServiceFilter {
public:
    bool Accept(const brpc::ServerNode& server) const override {
        servers.push_back(server);
        return true;
    }
    mutable std::vector<brpc::ServerNode> servers;
};

int main() {
    butil::TempFile tmp;
    FILE* fp = fopen(tmp.fname(), "w");
    fputs("# This line is ignored\n"
          "10.24.234.17:8080 tag1  # a comment\n"
          "10.24.234.18:8080  # a comment without tag\n"
          "10.24.234.18:8080  # same server, another comment\n"
          "10.24.234.19:8080 #\n", fp);
    fclose(fp);

    RecordingFilter filter;
    brpc::ChannelOptions options;
    options.ns_filter = &filter;
    brpc::Channel channel;
    const std::string url = std::string("file://") + tmp.fname();
    if (channel.Init(url.c_str(), "rr", &options) != 0) {
        return 2;
    }
    for (size_t i = 0; i < filter.servers.size(); ++i) {
        printf("server[%zu] addr=%s tag=\"%s\"\n", i,
               butil::endpoint2str(filter.servers[i].addr).c_str(),
               filter.servers[i].tag.c_str());
    }
    fflush(stdout);
    _exit(0);
}

Output on master:

server[0] addr=10.24.234.17:8080 tag="tag1"
server[1] addr=10.24.234.18:8080 tag="# a comment without tag"
server[2] addr=10.24.234.18:8080 tag="# same server, another comment"
server[3] addr=10.24.234.19:8080 tag="#"

Expected behavior

server[0] addr=10.24.234.17:8080 tag="tag1"
server[1] addr=10.24.234.18:8080 tag=""
server[2] addr=10.24.234.19:8080 tag=""

Versions
OS: Ubuntu 24.04, x86_64
Compiler: gcc 13.3.0
brpc: master @ 05abb1c3
protobuf: 28.3

Additional context/screenshots

  • A related case that this report does not cover: in 10.0.0.3:80#c (no blank before #) the whole token is taken as the address, so by the code the line is rejected as "Invalid address" (read from the code, not run). Should the address also end at #? That could change unix: paths that contain #.
  • A PR with the fix (one condition in SplitIntoServerAndTag()) and a unit test follows.
  • This report was prepared with an AI coding assistant (Claude Code, model claude-fable-5-2): the bug was found by reading the code and reproduced with the program above on master @ 05abb1c3 on a Linux x86_64 machine; the output shown is from that run.
Ngôn ngữ chính
C++
Star
17.6k
Fork
4.2k
Merge trung bình
3 ngày 17 giờ
Pull request đã merge (30 ngày)
72

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/brpc

Tất cả issue của apache/brpc

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.