file:// naming service takes a comment after the address as the tag
Mantenedores costumam responder em até 2 dias
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- cpp
- Domínio
- backend-api-design
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- C++
- Estrelas
- 17.6k
- Forks
- 4.2k
- Merge médio
- 3d 17h
- PRs com merge (30d)
- 72
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de apache/brpc
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 2 dias
-
endpoint2hostname() prints a byte-swapped port for IPv6 endpointsTalvez já em andamento @0z5a assumiu há 8 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
Mantenedores costumam responder em até 2 dias
-
perf(butil): ARM64 (aarch64) performance and modernisation improvements across atomics, CRC32C, spin-wait hints, and fast timersTalvez já em andamento @jimmystewpot assumiu há 2 dias. Aberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 12/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
Mantenedores costumam responder em até 2 dias
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 20/100
apache/brpc#3707 · 3 comentários ·
Mantenedores costumam responder em até 2 dias
Todas as issues de apache/brpc
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
protocolbuffers/protobuf#31768 ·
Mantenedores costumam responder em até 1 dia
-
Needs: Triage :mag: Platform: Android
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
react/react-native#60167 ·
Mantenedores costumam responder em até 2 dias
-
Level format documentationAbertadocumentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
-
tests: ofx_render_test doesn't compile against FFmpeg 4.x (const AVCodec* to av_find_best_stream)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
NatronGitHub/openfx-io#221 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
subsurface/subsurface#5145 ·
Mantenedores costumam responder em até 2 dias