Skip to content

Commit 33a492e

Browse files
committed
master pull
1 parent 869b25f commit 33a492e

File tree

9 files changed

+15
-172
lines changed

9 files changed

+15
-172
lines changed

core/src/main/java/io/grpc/internal/ManagedClientDisconnectTransport.java renamed to core/src/main/java/io/grpc/internal/ClientTransportWithDisconnectReason.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
*/
2626
@ThreadSafe
27-
public interface ManagedClientDisconnectTransport extends ClientTransport {
27+
public interface ClientTransportWithDisconnectReason extends ClientTransport {
2828

2929
/**
3030
* Initiates a forceful shutdown in which preexisting and new calls are closed. Existing calls

core/src/main/java/io/grpc/internal/DisconnectError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ public interface DisconnectError {
3131
* @return The formatted error tag string.
3232
*/
3333
String toErrorString();
34-
}
34+
}

core/src/main/java/io/grpc/internal/GoAwayDisconnectError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ public boolean equals(Object o) {
6161
public int hashCode() {
6262
return errorCode.hashCode();
6363
}
64-
}
64+
}

core/src/main/java/io/grpc/internal/KeepAliveManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ public interface KeepAlivePinger {
262262
* Default client side {@link KeepAlivePinger}.
263263
*/
264264
public static final class ClientKeepAlivePinger implements KeepAlivePinger {
265-
private final ManagedClientDisconnectTransport transport;
265+
private final ClientTransportWithDisconnectReason transport;
266266

267-
public ClientKeepAlivePinger(ManagedClientDisconnectTransport transport) {
267+
public ClientKeepAlivePinger(ClientTransportWithDisconnectReason transport) {
268268
this.transport = transport;
269269
}
270270

core/src/main/java/io/grpc/internal/SimpleDisconnectError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ public enum SimpleDisconnectError implements DisconnectError {
6565
public String toErrorString() {
6666
return this.errorTag;
6767
}
68-
}
68+
}

core/src/main/java/io/grpc/internal/SubchannelMetrics.java

Lines changed: 0 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -105,164 +105,4 @@ public void recordDisconnection(String target, String backendService, String loc
105105
ImmutableList.of(target),
106106
ImmutableList.of(securityLevel, backendService, locality));
107107
}
108-
109-
/**
110-
* Represents the reason for a subchannel failure.
111-
*/
112-
public enum DisconnectError {
113-
114-
/**
115-
* Represents an HTTP/2 GOAWAY frame. The specific error code
116-
* (e.g., "NO_ERROR", "PROTOCOL_ERROR") should be handled separately
117-
* as it is a dynamic part of the error.
118-
* See RFC 9113 for error codes: https://www.rfc-editor.org/rfc/rfc9113.html#name-error-codes
119-
*/
120-
GOAWAY("goaway"),
121-
122-
/**
123-
* The subchannel was shut down for various reasons like parent channel shutdown,
124-
* idleness, or load balancing policy changes.
125-
*/
126-
SUBCHANNEL_SHUTDOWN("subchannel shutdown"),
127-
128-
/**
129-
* Connection was reset (e.g., ECONNRESET, WSAECONNERESET).
130-
*/
131-
CONNECTION_RESET("connection reset"),
132-
133-
/**
134-
* Connection timed out (e.g., ETIMEDOUT, WSAETIMEDOUT), including closures
135-
* from gRPC keepalives.
136-
*/
137-
CONNECTION_TIMED_OUT("connection timed out"),
138-
139-
/**
140-
* Connection was aborted (e.g., ECONNABORTED, WSAECONNABORTED).
141-
*/
142-
CONNECTION_ABORTED("connection aborted"),
143-
144-
/**
145-
* Any socket error not covered by other specific disconnect errors.
146-
*/
147-
SOCKET_ERROR("socket error"),
148-
149-
/**
150-
* A catch-all for any other unclassified reason.
151-
*/
152-
UNKNOWN("unknown");
153-
154-
private final String errorTag;
155-
156-
/**
157-
* Private constructor to associate a description with each enum constant.
158-
*
159-
* @param errorTag The detailed explanation of the error.
160-
*/
161-
DisconnectError(String errorTag) {
162-
this.errorTag = errorTag;
163-
}
164-
165-
/**
166-
* Gets the error string suitable for use as a metric tag.
167-
*
168-
* <p>If the reason is {@code GOAWAY}, this method requires the specific
169-
* HTTP/2 error code to create the complete tag (e.g., "goaway PROTOCOL_ERROR").
170-
* For all other reasons, the parameter is ignored.</p>
171-
*
172-
* @param goawayErrorCode The specific HTTP/2 error code. This is only
173-
* used if the reason is GOAWAY and should not be null in that case.
174-
* @return The formatted error string.
175-
*/
176-
public String getErrorString(@Nullable String goawayErrorCode) {
177-
if (this == GOAWAY) {
178-
if (goawayErrorCode == null || goawayErrorCode.isEmpty()) {
179-
// Return the base tag if the code is missing, or consider throwing an exception
180-
// throw new IllegalArgumentException("goawayErrorCode is required for GOAWAY reason.");
181-
return this.errorTag;
182-
}
183-
return this.errorTag + " " + goawayErrorCode;
184-
}
185-
return this.errorTag;
186-
}
187-
}
188-
189-
/**
190-
* Represents the reason for a subchannel failure.
191-
*/
192-
public enum DisconnectError {
193-
194-
/**
195-
* Represents an HTTP/2 GOAWAY frame. The specific error code
196-
* (e.g., "NO_ERROR", "PROTOCOL_ERROR") should be handled separately
197-
* as it is a dynamic part of the error.
198-
* See RFC 9113 for error codes: https://www.rfc-editor.org/rfc/rfc9113.html#name-error-codes
199-
*/
200-
GOAWAY("goaway"),
201-
202-
/**
203-
* The subchannel was shut down for various reasons like parent channel shutdown,
204-
* idleness, or load balancing policy changes.
205-
*/
206-
SUBCHANNEL_SHUTDOWN("subchannel shutdown"),
207-
208-
/**
209-
* Connection was reset (e.g., ECONNRESET, WSAECONNERESET).
210-
*/
211-
CONNECTION_RESET("connection reset"),
212-
213-
/**
214-
* Connection timed out (e.g., ETIMEDOUT, WSAETIMEDOUT), including closures
215-
* from gRPC keepalives.
216-
*/
217-
CONNECTION_TIMED_OUT("connection timed out"),
218-
219-
/**
220-
* Connection was aborted (e.g., ECONNABORTED, WSAECONNABORTED).
221-
*/
222-
CONNECTION_ABORTED("connection aborted"),
223-
224-
/**
225-
* Any socket error not covered by other specific disconnect errors.
226-
*/
227-
SOCKET_ERROR("socket error"),
228-
229-
/**
230-
* A catch-all for any other unclassified reason.
231-
*/
232-
UNKNOWN("unknown");
233-
234-
private final String errorTag;
235-
236-
/**
237-
* Private constructor to associate a description with each enum constant.
238-
*
239-
* @param errorTag The detailed explanation of the error.
240-
*/
241-
DisconnectError(String errorTag) {
242-
this.errorTag = errorTag;
243-
}
244-
245-
/**
246-
* Gets the error string suitable for use as a metric tag.
247-
*
248-
* <p>If the reason is {@code GOAWAY}, this method requires the specific
249-
* HTTP/2 error code to create the complete tag (e.g., "goaway PROTOCOL_ERROR").
250-
* For all other reasons, the parameter is ignored.</p>
251-
*
252-
* @param goawayErrorCode The specific HTTP/2 error code. This is only
253-
* used if the reason is GOAWAY and should not be null in that case.
254-
* @return The formatted error string.
255-
*/
256-
public String getErrorString(@Nullable String goawayErrorCode) {
257-
if (this == GOAWAY) {
258-
if (goawayErrorCode == null || goawayErrorCode.isEmpty()) {
259-
// Return the base tag if the code is missing, or consider throwing an exception
260-
// throw new IllegalArgumentException("goawayErrorCode is required for GOAWAY reason.");
261-
return this.errorTag;
262-
}
263-
return this.errorTag + " " + goawayErrorCode;
264-
}
265-
return this.errorTag;
266-
}
267-
}
268108
}

core/src/test/java/io/grpc/internal/KeepAliveManagerTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public void keepAlivePingDelayedByIncomingData() {
105105

106106
@Test
107107
public void clientKeepAlivePinger_pingTimeout() {
108-
ManagedClientDisconnectTransport transport = mock(ManagedClientDisconnectTransport.class);
108+
ClientTransportWithDisconnectReason transport =
109+
mock(ClientTransportWithDisconnectReason.class);
109110
ClientKeepAlivePinger pinger = new ClientKeepAlivePinger(transport);
110111

111112
pinger.onPingTimeout();
@@ -121,7 +122,8 @@ public void clientKeepAlivePinger_pingTimeout() {
121122

122123
@Test
123124
public void clientKeepAlivePinger_pingFailure() {
124-
ManagedClientDisconnectTransport transport = mock(ManagedClientDisconnectTransport.class);
125+
ClientTransportWithDisconnectReason transport =
126+
mock(ClientTransportWithDisconnectReason.class);
125127
ClientKeepAlivePinger pinger = new ClientKeepAlivePinger(transport);
126128
pinger.ping();
127129
ArgumentCaptor<ClientTransport.PingCallback> pingCallbackCaptor =

netty/src/main/java/io/grpc/netty/NettyClientTransport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
import io.grpc.MethodDescriptor;
3737
import io.grpc.Status;
3838
import io.grpc.internal.ClientStream;
39+
import io.grpc.internal.ClientTransportWithDisconnectReason;
3940
import io.grpc.internal.ConnectionClientTransport;
4041
import io.grpc.internal.DisconnectError;
4142
import io.grpc.internal.FailingClientStream;
4243
import io.grpc.internal.GrpcUtil;
4344
import io.grpc.internal.Http2Ping;
4445
import io.grpc.internal.KeepAliveManager;
4546
import io.grpc.internal.KeepAliveManager.ClientKeepAlivePinger;
46-
import io.grpc.internal.ManagedClientDisconnectTransport;
4747
import io.grpc.internal.SimpleDisconnectError;
4848
import io.grpc.internal.StatsTraceContext;
4949
import io.grpc.internal.TransportTracer;
@@ -71,7 +71,8 @@
7171
/**
7272
* A Netty-based {@link ConnectionClientTransport} implementation.
7373
*/
74-
class NettyClientTransport implements ConnectionClientTransport, ManagedClientDisconnectTransport {
74+
class NettyClientTransport implements ConnectionClientTransport,
75+
ClientTransportWithDisconnectReason {
7576

7677
private final InternalLogId logId;
7778
private final Map<ChannelOption<?>, ?> channelOptions;

okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import io.grpc.TlsChannelCredentials;
4848
import io.grpc.internal.CertificateUtils;
4949
import io.grpc.internal.ClientStreamListener.RpcProgress;
50+
import io.grpc.internal.ClientTransportWithDisconnectReason;
5051
import io.grpc.internal.ConnectionClientTransport;
5152
import io.grpc.internal.DisconnectError;
5253
import io.grpc.internal.GoAwayDisconnectError;
@@ -56,7 +57,6 @@
5657
import io.grpc.internal.InUseStateAggregator;
5758
import io.grpc.internal.KeepAliveManager;
5859
import io.grpc.internal.KeepAliveManager.ClientKeepAlivePinger;
59-
import io.grpc.internal.ManagedClientDisconnectTransport;
6060
import io.grpc.internal.NoopSslSession;
6161
import io.grpc.internal.SerializingExecutor;
6262
import io.grpc.internal.SimpleDisconnectError;
@@ -133,7 +133,7 @@
133133
* A okhttp-based {@link ConnectionClientTransport} implementation.
134134
*/
135135
class OkHttpClientTransport implements ConnectionClientTransport, TransportExceptionHandler,
136-
OutboundFlowController.Transport, ManagedClientDisconnectTransport {
136+
OutboundFlowController.Transport, ClientTransportWithDisconnectReason {
137137
private static final Map<ErrorCode, Status> ERROR_CODE_TO_STATUS = buildErrorCodeToStatusMap();
138138
private static final Logger log = Logger.getLogger(OkHttpClientTransport.class.getName());
139139
private static final String GRPC_ENABLE_PER_RPC_AUTHORITY_CHECK =

0 commit comments

Comments
 (0)