file:// naming service takes a comment after the address as the tag
維護者通常 2 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- cpp
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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 changeunix: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.
- 主要語言
- C++
- 星號
- 17.6k
- 分支
- 4.2k
- 平均合併
- 3 天 17 小時
- 30 天內合併 PR
- 72
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
apache/brpc 的其他 Issue
-
難度 1/5 1-3 小時 新手友好度 88/100
維護者通常 2 天內回覆
-
endpoint2hostname() prints a byte-swapped port for IPv6 endpoints可能已有人在做 @0z5a 於 8 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 2 天內回覆
-
perf(butil): ARM64 (aarch64) performance and modernisation improvements across atomics, CRC32C, spin-wait hints, and fast timers可能已有人在做 @jimmystewpot 於 2 天前認領。 未關閉
難度 5/5 一週以上 新手友好度 12/100
維護者通常 2 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
維護者通常 2 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 20/100
維護者通常 2 天內回覆
相似的 Issue
-
agent:Windows bug in progress pri:medium sev:low testing windows
難度 1/5 1 小時以內 新手友好度 91/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 77/100
protocolbuffers/protobuf#31768 ·
維護者通常 1 天內回覆
-
Android: with view recycling on, a recycled View keeps its nextFocusLeft可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉Needs: Triage :mag: Platform: Android
難度 2/5 1-3 小時 新手友好度 78/100
react/react-native#60167 ·
維護者通常 2 天內回覆
-
documentation
難度 2/5 1-3 小時 新手友好度 63/100
-
clang-include-cleaner cmake
難度 2/5 1-3 小時 新手友好度 69/100
llvm/llvm-project#244374 · 1 則留言 ·
維護者通常 1 天內回覆