Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: remember last pick status in no real stream #11851

Merged
merged 9 commits into from
Feb 14, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ final void reprocess(@Nullable SubchannelPicker picker) {

for (final PendingStream stream : toProcess) {
PickResult pickResult = picker.pickSubchannel(stream.args);
if (!pickResult.hasResult()) {
stream.lastPickStatus = pickResult.getStatus();
}
CallOptions callOptions = stream.args.getCallOptions();
// User code provided authority takes precedence over the LB provided one.
if (callOptions.getAuthority() == null && pickResult.getAuthorityOverride() != null) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/io/grpc/internal/DelayedStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DelayedStream implements ClientStream {
private long streamSetTimeNanos;
// No need to synchronize; start() synchronization provides a happens-before
private List<Runnable> preStartPendingCalls = new ArrayList<>();
protected Status lastPickStatus;

@Override
public void setMaxInboundMessageSize(final int maxSize) {
Expand Down Expand Up @@ -109,6 +110,7 @@ public void appendTimeoutInsight(InsightBuilder insight) {
} else {
insight.appendKeyValue("buffered_nanos", System.nanoTime() - startTimeNanos);
insight.append("waiting_for_connection");
insight.append(lastPickStatus);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public void pendingStream_appendTimeoutInsight_waitForReady() {
InsightBuilder insight = new InsightBuilder();
stream.appendTimeoutInsight(insight);
assertThat(insight.toString())
.matches("\\[wait_for_ready, buffered_nanos=[0-9]+\\, waiting_for_connection]");
.matches("\\[wait_for_ready, buffered_nanos=[0-9]+\\, waiting_for_connection, null]");
}

private static TransportProvider newTransportProvider(final ClientTransport transport) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/io/grpc/internal/DelayedStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ public void appendTimeoutInsight_realStreamNotSet() {
InsightBuilder insight = new InsightBuilder();
stream.start(listener);
stream.appendTimeoutInsight(insight);
assertThat(insight.toString()).matches("\\[buffered_nanos=[0-9]+\\, waiting_for_connection]");
assertThat(insight.toString())
.matches("\\[buffered_nanos=[0-9]+\\, waiting_for_connection, null]");
}

@Test
Expand Down
Loading