Skip to content

Fix gRPC UNAVAILABLE error - #168

Merged
sohyun-ku merged 4 commits into
naver:developfrom
NineTIN:fix-grpc-unavailable
Jun 2, 2026
Merged

sohyun-ku merged 4 commits into
naver:developfrom
NineTIN:fix-grpc-unavailable

Conversation

@NineTIN

@NineTIN NineTIN commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

#78 와 동일한 StatusRuntimeException: UNAVAILABLE 문제를 겪고 있었고,
여러 가지로 확인해보다가 원인으로 보이는 부분을 수정해봤더니 문제가 재현되지 않아 PR 보냅니다.

환경

  • 쿠버네티스 환경
  • Scavenger Agent → [plaintext gRPC] → Ingress L7 (ALB, HTTPS)

확인한 사항

  • HTTPS 통신은 서비스 <-> collector 간 문제 없이 동작
  • gRPC는 reflection이 꺼져 있어서 proto를 직접 지정해 호출해보니 정상적으로 통신됨
    → 네트워크나 단순 연결 문제는 아닌 것으로 판단했습니다.

원인

Ingress(L7)가 HTTPS(TLS) 연결을 기대하는 상태에서 Agent는 usePlaintext() 설정으로 평문 gRPC 요청을 보내고 있었습니다.

private ManagedChannel createChannel(int maxMessageSize) {
return OkHttpChannelBuilder.forTarget(this.host)
.maxInboundMessageSize(maxMessageSize)
.usePlaintext()
.build();

이 구성에서는 TLS Handshake가 성립되지 않아 연결이 즉시 종료되고 그로인해 Agent에서는 스트림이 비정상 종료된 것으로 인식되어 UNAVAILABLE 에러가 발생하는 것이 아닐까? 하고 가정했습니다.

해결

  • Collector URL이 HTTPS인 경우(TLS 사용), gRPC 클라이언트가 usePlaintext() 대신 useTransportSecurity()를 사용하도록 조건 분기 추가

테스트

  • 동일한 환경(Scavenger Agent → [plaintext gRPC] → Ingress L7 (ALB, HTTPS))에서 재현 확인
  • 수정 적용 후, 동일 조건에서 StatusRuntimeException: UNAVAILABLE 발생하지 않음을 확인
  • gRPC 스트림이 정상적으로 유지되는 것 확인

@NineTIN
NineTIN requested review from a team and junoyoon as code owners April 14, 2026 13:48
@github-actions

github-actions Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

Scavenger Test Results

177 files  177 suites   4m 36s ⏱️
307 tests 300 ✅ 7 💤 0 ❌
334 runs  327 ✅ 7 💤 0 ❌

Results for commit 61eb65a.

♻️ This comment has been updated with latest results.

@taeyeon-Kim taeyeon-Kim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 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). 🙏

Comment on lines 35 to 40
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();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 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. 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at the PR.
I’ve updated it based on your comments.

@taeyeon-Kim taeyeon-Kim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍

@kojandy kojandy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@NineTIN

NineTIN commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

머지된 이후 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the names

@sohyun-ku

Copy link
Copy Markdown
Contributor

@NineTIN
Thank you for the valuable PR👍
We are currently in the process of coordinating the overall project priorities and the next release cycle.
Please understand that it may take some time before the actual release. We appreciate your patience in the meantime.

@sohyun-ku
sohyun-ku merged commit f09c903 into naver:develop Jun 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants