Skip to content

Commit 41f3cc2

Browse files
committed
Merge remote-tracking branch 'origin/master' into rls-control-plane-channel-monitor-state
2 parents dffb376 + 4843256 commit 41f3cc2

File tree

74 files changed

+806
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+806
-542
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module(
22
name = "grpc-java",
33
compatibility_level = 0,
44
repo_name = "io_grpc_grpc_java",
5-
version = "1.77.0-SNAPSHOT", # CURRENT_GRPC_VERSION
5+
version = "1.78.0-SNAPSHOT", # CURRENT_GRPC_VERSION
66
)
77

88
# GRPC_DEPS_START

api/src/main/java/io/grpc/NameResolver.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ public void onError(Status error) {
9797

9898
@Override
9999
public void onResult(ResolutionResult resolutionResult) {
100-
listener.onAddresses(resolutionResult.getAddressesOrError().getValue(),
101-
resolutionResult.getAttributes());
100+
StatusOr<List<EquivalentAddressGroup>> addressesOrError =
101+
resolutionResult.getAddressesOrError();
102+
if (addressesOrError.hasValue()) {
103+
listener.onAddresses(addressesOrError.getValue(),
104+
resolutionResult.getAttributes());
105+
} else {
106+
listener.onError(addressesOrError.getStatus());
107+
}
102108
}
103109
});
104110
}

api/src/test/java/io/grpc/NameResolverTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,56 @@ public void resolutionResult_hashCode() {
192192
Objects.hashCode(StatusOr.fromValue(ADDRESSES), ATTRIBUTES, CONFIG));
193193
}
194194

195+
@Test
196+
public void startOnOldListener_resolverReportsError() {
197+
final boolean[] onErrorCalled = new boolean[1];
198+
final Status[] receivedError = new Status[1];
199+
200+
NameResolver resolver = new NameResolver() {
201+
@Override
202+
public String getServiceAuthority() {
203+
return "example.com";
204+
}
205+
206+
@Override
207+
public void shutdown() {
208+
}
209+
210+
@Override
211+
public void start(Listener2 listener2) {
212+
ResolutionResult errorResult = ResolutionResult.newBuilder()
213+
.setAddressesOrError(StatusOr.fromStatus(
214+
Status.UNAVAILABLE
215+
.withDescription("DNS resolution failed with UNAVAILABLE")))
216+
.build();
217+
218+
listener2.onResult(errorResult);
219+
}
220+
};
221+
222+
NameResolver.Listener listener = new NameResolver.Listener() {
223+
@Override
224+
public void onAddresses(
225+
List<EquivalentAddressGroup> servers,
226+
Attributes attributes) {
227+
throw new AssertionError("Called onAddresses on error");
228+
}
229+
230+
@Override
231+
public void onError(Status error) {
232+
onErrorCalled[0] = true;
233+
receivedError[0] = error;
234+
}
235+
};
236+
237+
resolver.start(listener);
238+
239+
assertThat(onErrorCalled[0]).isTrue();
240+
assertThat(receivedError[0].getCode()).isEqualTo(Status.Code.UNAVAILABLE);
241+
assertThat(receivedError[0].getDescription()).isEqualTo(
242+
"DNS resolution failed with UNAVAILABLE");
243+
}
244+
195245
private static class FakeSocketAddress extends SocketAddress {
196246
final String name;
197247

binder/src/androidTest/java/io/grpc/binder/internal/BinderClientTransportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
import io.grpc.Status.Code;
4040
import io.grpc.binder.AndroidComponentAddress;
4141
import io.grpc.binder.BinderServerBuilder;
42-
import io.grpc.binder.FakeDeadBinder;
4342
import io.grpc.binder.HostServices;
4443
import io.grpc.binder.SecurityPolicy;
44+
import io.grpc.binder.internal.FakeDeadBinder;
4545
import io.grpc.binder.internal.OneWayBinderProxies.BlackHoleOneWayBinderProxy;
4646
import io.grpc.binder.internal.OneWayBinderProxies.BlockingBinderDecorator;
4747
import io.grpc.binder.internal.OneWayBinderProxies.ThrowingOneWayBinderProxy;

binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java

Lines changed: 99 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -148,31 +148,33 @@ public synchronized void onUnbound(Status reason) {
148148
@Override
149149
public synchronized Runnable start(Listener clientTransportListener) {
150150
this.clientTransportListener = checkNotNull(clientTransportListener);
151-
return () -> {
152-
synchronized (BinderClientTransport.this) {
153-
if (inState(TransportState.NOT_STARTED)) {
154-
setState(TransportState.SETUP);
155-
try {
156-
if (preAuthorizeServer) {
157-
preAuthorize(serviceBinding.resolve());
158-
} else {
159-
serviceBinding.bind();
160-
}
161-
} catch (StatusException e) {
162-
shutdownInternal(e.getStatus(), true);
163-
return;
164-
}
165-
if (readyTimeoutMillis >= 0) {
166-
readyTimeoutFuture =
167-
getScheduledExecutorService()
168-
.schedule(
169-
BinderClientTransport.this::onReadyTimeout,
170-
readyTimeoutMillis,
171-
MILLISECONDS);
172-
}
173-
}
151+
return this::postStartRunnable;
152+
}
153+
154+
private synchronized void postStartRunnable() {
155+
if (!inState(TransportState.NOT_STARTED)) {
156+
return;
157+
}
158+
159+
setState(TransportState.SETUP);
160+
161+
try {
162+
if (preAuthorizeServer) {
163+
preAuthorize(serviceBinding.resolve());
164+
} else {
165+
serviceBinding.bind();
174166
}
175-
};
167+
} catch (StatusException e) {
168+
shutdownInternal(e.getStatus(), true);
169+
return;
170+
}
171+
172+
if (readyTimeoutMillis >= 0) {
173+
readyTimeoutFuture =
174+
getScheduledExecutorService()
175+
.schedule(
176+
BinderClientTransport.this::onReadyTimeout, readyTimeoutMillis, MILLISECONDS);
177+
}
176178
}
177179

178180
@GuardedBy("this")
@@ -204,13 +206,16 @@ public void onFailure(Throwable t) {
204206
}
205207

206208
private synchronized void handlePreAuthResult(Status authorization) {
207-
if (inState(TransportState.SETUP)) {
208-
if (!authorization.isOk()) {
209-
shutdownInternal(authorization, true);
210-
} else {
211-
serviceBinding.bind();
212-
}
209+
if (!inState(TransportState.SETUP)) {
210+
return;
211+
}
212+
213+
if (!authorization.isOk()) {
214+
shutdownInternal(authorization, true);
215+
return;
213216
}
217+
218+
serviceBinding.bind();
214219
}
215220

216221
private synchronized void onReadyTimeout() {
@@ -252,17 +257,17 @@ public synchronized ClientStream newStream(
252257
Status failure = Status.INTERNAL.withDescription("Clashing call IDs");
253258
shutdownInternal(failure, true);
254259
return newFailingClientStream(failure, attributes, headers, tracers);
260+
}
261+
262+
if (inbound.countsForInUse() && numInUseStreams.getAndIncrement() == 0) {
263+
clientTransportListener.transportInUse(true);
264+
}
265+
Outbound.ClientOutbound outbound =
266+
new Outbound.ClientOutbound(this, callId, method, headers, statsTraceContext);
267+
if (method.getType().clientSendsOneMessage()) {
268+
return new SingleMessageClientStream(inbound, outbound, attributes);
255269
} else {
256-
if (inbound.countsForInUse() && numInUseStreams.getAndIncrement() == 0) {
257-
clientTransportListener.transportInUse(true);
258-
}
259-
Outbound.ClientOutbound outbound =
260-
new Outbound.ClientOutbound(this, callId, method, headers, statsTraceContext);
261-
if (method.getType().clientSendsOneMessage()) {
262-
return new SingleMessageClientStream(inbound, outbound, attributes);
263-
} else {
264-
return new MultiMessageClientStream(inbound, outbound, attributes);
265-
}
270+
return new MultiMessageClientStream(inbound, outbound, attributes);
266271
}
267272
}
268273

@@ -314,39 +319,46 @@ void notifyTerminated() {
314319
@Override
315320
@GuardedBy("this")
316321
protected void handleSetupTransport(Parcel parcel) {
317-
int remoteUid = Binder.getCallingUid();
318-
if (inState(TransportState.SETUP)) {
319-
int version = parcel.readInt();
320-
IBinder binder = parcel.readStrongBinder();
321-
if (version != WIRE_FORMAT_VERSION) {
322-
shutdownInternal(Status.UNAVAILABLE.withDescription("Wire format version mismatch"), true);
323-
} else if (binder == null) {
324-
shutdownInternal(
325-
Status.UNAVAILABLE.withDescription("Malformed SETUP_TRANSPORT data"), true);
326-
} else if (!setOutgoingBinder(OneWayBinderProxy.wrap(binder, offloadExecutor))) {
327-
shutdownInternal(
328-
Status.UNAVAILABLE.withDescription("Failed to observe outgoing binder"), true);
329-
} else {
330-
restrictIncomingBinderToCallsFrom(remoteUid);
331-
attributes = setSecurityAttrs(attributes, remoteUid);
332-
ListenableFuture<Status> authResultFuture =
333-
register(checkServerAuthorizationAsync(remoteUid));
334-
Futures.addCallback(
335-
authResultFuture,
336-
new FutureCallback<Status>() {
337-
@Override
338-
public void onSuccess(Status result) {
339-
handleAuthResult(result);
340-
}
341-
342-
@Override
343-
public void onFailure(Throwable t) {
344-
handleAuthResult(t);
345-
}
346-
},
347-
offloadExecutor);
348-
}
322+
if (!inState(TransportState.SETUP)) {
323+
return;
324+
}
325+
326+
int version = parcel.readInt();
327+
if (version != WIRE_FORMAT_VERSION) {
328+
shutdownInternal(Status.UNAVAILABLE.withDescription("Wire format version mismatch"), true);
329+
return;
330+
}
331+
332+
IBinder binder = parcel.readStrongBinder();
333+
if (binder == null) {
334+
shutdownInternal(Status.UNAVAILABLE.withDescription("Malformed SETUP_TRANSPORT data"), true);
335+
return;
336+
}
337+
338+
if (!setOutgoingBinder(OneWayBinderProxy.wrap(binder, offloadExecutor))) {
339+
shutdownInternal(
340+
Status.UNAVAILABLE.withDescription("Failed to observe outgoing binder"), true);
341+
return;
349342
}
343+
344+
int remoteUid = Binder.getCallingUid();
345+
restrictIncomingBinderToCallsFrom(remoteUid);
346+
attributes = setSecurityAttrs(attributes, remoteUid);
347+
ListenableFuture<Status> authResultFuture = register(checkServerAuthorizationAsync(remoteUid));
348+
Futures.addCallback(
349+
authResultFuture,
350+
new FutureCallback<Status>() {
351+
@Override
352+
public void onSuccess(Status result) {
353+
handleAuthResult(result);
354+
}
355+
356+
@Override
357+
public void onFailure(Throwable t) {
358+
handleAuthResult(t);
359+
}
360+
},
361+
offloadExecutor);
350362
}
351363

352364
private ListenableFuture<Status> checkServerAuthorizationAsync(int remoteUid) {
@@ -356,18 +368,21 @@ private ListenableFuture<Status> checkServerAuthorizationAsync(int remoteUid) {
356368
}
357369

358370
private synchronized void handleAuthResult(Status authorization) {
359-
if (inState(TransportState.SETUP)) {
360-
if (!authorization.isOk()) {
361-
shutdownInternal(authorization, true);
362-
} else {
363-
setState(TransportState.READY);
364-
attributes = clientTransportListener.filterTransport(attributes);
365-
clientTransportListener.transportReady();
366-
if (readyTimeoutFuture != null) {
367-
readyTimeoutFuture.cancel(false);
368-
readyTimeoutFuture = null;
369-
}
370-
}
371+
if (!inState(TransportState.SETUP)) {
372+
return;
373+
}
374+
375+
if (!authorization.isOk()) {
376+
shutdownInternal(authorization, true);
377+
return;
378+
}
379+
380+
setState(TransportState.READY);
381+
attributes = clientTransportListener.filterTransport(attributes);
382+
clientTransportListener.transportReady();
383+
if (readyTimeoutFuture != null) {
384+
readyTimeoutFuture.cancel(false);
385+
readyTimeoutFuture = null;
371386
}
372387
}
373388

binder/src/main/java/io/grpc/binder/internal/BinderServerTransport.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,22 @@ public BinderServerTransport(
6969
*/
7070
public synchronized void start(ServerTransportListener serverTransportListener) {
7171
this.listenerPromise.set(serverTransportListener);
72-
if (!isShutdown()) {
73-
sendSetupTransaction();
74-
// Check we're not shutdown again, since a failure inside sendSetupTransaction (or a callback
75-
// it triggers), could have shut us down.
76-
if (!isShutdown()) {
77-
setState(TransportState.READY);
78-
attributes = serverTransportListener.transportReady(attributes);
79-
}
72+
if (isShutdown()) {
73+
// It's unlikely, but we could be shutdown externally between construction and start(). One
74+
// possible cause is an extremely short handshake timeout.
75+
return;
8076
}
77+
78+
sendSetupTransaction();
79+
80+
// Check we're not shutdown again, since a failure inside sendSetupTransaction (or a callback
81+
// it triggers), could have shut us down.
82+
if (isShutdown()) {
83+
return;
84+
}
85+
86+
setState(TransportState.READY);
87+
attributes = serverTransportListener.transportReady(attributes);
8188
}
8289

8390
StatsTraceContext createStatsTraceContext(String methodName, Metadata headers) {
@@ -92,10 +99,10 @@ StatsTraceContext createStatsTraceContext(String methodName, Metadata headers) {
9299
synchronized Status startStream(ServerStream stream, String methodName, Metadata headers) {
93100
if (isShutdown()) {
94101
return Status.UNAVAILABLE.withDescription("transport is shutdown");
95-
} else {
96-
listenerPromise.get().streamCreated(stream, methodName, headers);
97-
return Status.OK;
98102
}
103+
104+
listenerPromise.get().streamCreated(stream, methodName, headers);
105+
return Status.OK;
99106
}
100107

101108
@Override

binder/src/testFixtures/java/io/grpc/binder/FakeDeadBinder.java renamed to binder/src/testFixtures/java/io/grpc/binder/internal/FakeDeadBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.grpc.binder;
17+
package io.grpc.binder.internal;
1818

1919
import android.os.DeadObjectException;
2020
import android.os.IBinder;

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ subprojects {
2121
apply plugin: "net.ltgt.errorprone"
2222

2323
group = "io.grpc"
24-
version = "1.77.0-SNAPSHOT" // CURRENT_GRPC_VERSION
24+
version = "1.78.0-SNAPSHOT" // CURRENT_GRPC_VERSION
2525

2626
repositories {
2727
maven { // The google mirror is less flaky than mavenCentral()

compiler/src/test/golden/TestDeprecatedService.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
88
* </pre>
99
*/
1010
@javax.annotation.Generated(
11-
value = "by gRPC proto compiler (version 1.77.0-SNAPSHOT)",
11+
value = "by gRPC proto compiler (version 1.78.0-SNAPSHOT)",
1212
comments = "Source: grpc/testing/compiler/test.proto")
1313
@io.grpc.stub.annotations.GrpcGenerated
1414
@java.lang.Deprecated

compiler/src/test/golden/TestService.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import static io.grpc.MethodDescriptor.generateFullMethodName;
88
* </pre>
99
*/
1010
@javax.annotation.Generated(
11-
value = "by gRPC proto compiler (version 1.77.0-SNAPSHOT)",
11+
value = "by gRPC proto compiler (version 1.78.0-SNAPSHOT)",
1212
comments = "Source: grpc/testing/compiler/test.proto")
1313
@io.grpc.stub.annotations.GrpcGenerated
1414
public final class TestServiceGrpc {

0 commit comments

Comments
 (0)