Repository navigation
Fix gRPC UNAVAILABLE error - #168
Conversation
Scavenger Test Results177 files 177 suites 4m 36s ⏱️ Results for commit 61eb65a. ♻️ This comment has been updated with latest results. |
taeyeon-Kim
left a comment
There was a problem hiding this comment.
🎉 The root-cause analysis is spot on.
The V5 init-config endpoint at AgentController.kt:45 does request.requestURL.split("/")[2], which drops the URL scheme entirely — so the agent has no way to decide whether the gRPC channel should use TLS. Compared to the V4 endpoint at AgentController.kt:35 ("${splitUrl[0]}//${splitUrl[2]}"), which preserves the scheme, this was a clear design oversight.
Grounding the decision on config.serverUrl's scheme is the only correct answer here: the collector only listens on plaintext HTTP via Armeria (application.yml, server.port: -1 + protocols: HTTP), which means any request.requestURL-based detection would always be wrong behind a TLS-terminating proxy — exactly the environment this PR is fixing. 👍
Left one small nit about the boolean flag on the public constructor. Happy to approve once that's addressed (or feel free to decline if you'd rather keep the diff minimal). 🙏
| public GrpcClient(String host, boolean useTls) { | ||
| log.info("[scavenger] creating new grpc client. host is " + host + " tls=" + useTls); | ||
| this.host = host; | ||
|
|
||
| this.useTls = useTls; | ||
| createNewChannelIfShutdown(); | ||
| } |
There was a problem hiding this comment.
💭 Nit — extracting named factories to hide the boolean flag 🧹
The boolean useTls on the public constructor is a classic flag-argument smell: at call sites, new GrpcClient(url, true) doesn't tell the reader what true actually means. Since we only ever construct a client in one of two well-defined modes, named factory methods express the intent explicitly without any extra machinery:
public static GrpcClient plaintext(String host) { return new GrpcClient(host, false); }
public static GrpcClient tls(String host) { return new GrpcClient(host, true); }
private GrpcClient(String host, boolean useTls) {
log.info("[scavenger] creating new grpc client. host=" + host + " tls=" + useTls);
this.host = host;
this.useTls = useTls;
createNewChannelIfShutdown();
}Then in Publisher#getGrpcClient():
grpcClient = useTls ? GrpcClient.tls(target) : GrpcClient.plaintext(target);The boolean stays as a private field — no new enum or value object, so the agent stays lightweight — but the public surface becomes self-documenting. Feel free to skip if you'd rather keep the diff minimal. 🙂
There was a problem hiding this comment.
Thanks for taking a look at the PR.
I’ve updated it based on your comments.
|
머지된 이후 Maven Repository에는 언제쯤 반영되는지 알 수 있을까요? |
| public GrpcClient(String host) { | ||
| log.info("[scavenger] creating new grpc client. host is " + host); | ||
| this.host = host; | ||
| public static GrpcClient plaintext(String host) { |
There was a problem hiding this comment.
I’d suggest renaming these to something like createPlaintext and createTls.
Using create makes it immediately clear that these are factory methods responsible for instantiation, rather than configuration or transformation.
|
@NineTIN |
#78 와 동일한
StatusRuntimeException: UNAVAILABLE문제를 겪고 있었고,여러 가지로 확인해보다가 원인으로 보이는 부분을 수정해봤더니 문제가 재현되지 않아 PR 보냅니다.
환경
확인한 사항
→ 네트워크나 단순 연결 문제는 아닌 것으로 판단했습니다.
원인
Ingress(L7)가 HTTPS(TLS) 연결을 기대하는 상태에서 Agent는
usePlaintext()설정으로 평문 gRPC 요청을 보내고 있었습니다.scavenger/scavenger-agent-java/src/main/java/com/navercorp/scavenger/javaagent/publishing/GrpcClient.java
Lines 100 to 104 in c0fcd76
이 구성에서는 TLS Handshake가 성립되지 않아 연결이 즉시 종료되고 그로인해 Agent에서는 스트림이 비정상 종료된 것으로 인식되어
UNAVAILABLE에러가 발생하는 것이 아닐까? 하고 가정했습니다.해결
usePlaintext()대신useTransportSecurity()를 사용하도록 조건 분기 추가테스트
StatusRuntimeException: UNAVAILABLE발생하지 않음을 확인