• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #20325

19 Jun 2026 11:41AM UTC coverage: 88.881% (-0.005%) from 88.886%
#20325

push

github

web-flow
Revert "servlet: fix write when not ready in AsyncServletOutputStreamWriter (#12867)

This reverts commit 243b79ee5. The
approach taken of ensuring subsequent writes go through the container
thread via onWritePossible() hasn't eliminated the need for catching the
IllegalStateException (which you are catching and buffering the write if
it happens). We have observed that the UndertowInteropTest now hangs
instead of the earlier flaky failures due to uncaught exception. There
has been another PR https://github.com/grpc/grpc-java/pull/12732 for the
same issue that explicitly checks isReady.getAsBoolean() in addition to
the cached state, that's probably most reliable, because you don't have
to deal with callback scheduling and the state changing in the meantime.
We would like to proceed with that PR and revert this one.

@mgustimz

36532 of 41102 relevant lines covered (88.88%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/../api/src/main/java/io/grpc/Grpc.java
1
/*
2
 * Copyright 2016 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc;
18

19
import java.lang.annotation.Documented;
20
import java.lang.annotation.Retention;
21
import java.lang.annotation.RetentionPolicy;
22
import java.net.SocketAddress;
23
import java.net.URI;
24
import java.net.URISyntaxException;
25
import javax.net.ssl.SSLSession;
26

27
/**
28
 * Stuff that are part of the public API but are not bound to particular classes, e.g., static
29
 * methods, constants, attribute and context keys.
30
 */
31
public final class Grpc {
32
  private Grpc() {
33
  }
34

35
  /**
36
   * Attribute key for the remote address of a transport.
37
   */
38
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710")
39
  @TransportAttr
40
  public static final Attributes.Key<SocketAddress> TRANSPORT_ATTR_REMOTE_ADDR =
1✔
41
      Attributes.Key.create("io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR");
1✔
42

43
  /**
44
   * Attribute key for the local address of a transport.
45
   */
46
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710")
47
  @TransportAttr
48
  public static final Attributes.Key<SocketAddress> TRANSPORT_ATTR_LOCAL_ADDR =
1✔
49
      Attributes.Key.create("io.grpc.Grpc.TRANSPORT_ATTR_LOCAL_ADDR");
1✔
50

51
  /**
52
   * Attribute key for SSL session of a transport.
53
   */
54
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710")
55
  @TransportAttr
56
  public static final Attributes.Key<SSLSession> TRANSPORT_ATTR_SSL_SESSION =
1✔
57
      Attributes.Key.create("io.grpc.Grpc.TRANSPORT_ATTR_SSL_SESSION");
1✔
58

59
  /**
60
   * The value for the custom label of per-RPC metrics. Defaults to empty string when unset. Must
61
   * not be set to {@code null}.
62
   */
63
  public static final CallOptions.Key<String> CALL_OPTION_CUSTOM_LABEL =
1✔
64
      CallOptions.Key.createWithDefault("io.grpc.Grpc.CALL_OPTION_CUSTOM_LABEL", "");
1✔
65

66
  /**
67
   * Annotation for transport attributes. It follows the annotation semantics defined
68
   * by {@link Attributes}.
69
   */
70
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4972")
71
  @Retention(RetentionPolicy.SOURCE)
72
  @Documented
73
  public @interface TransportAttr {}
74

75
  /**
76
   * Creates a channel builder with a target string and credentials. The target can be either an RFC
77
   * 3986 URI, or an authority string.
78
   *
79
   * <p>Example URIs:
80
   * <ul>
81
   *   <li>{@code "dns:///foo.googleapis.com:8080"}</li>
82
   *   <li>{@code "dns:///foo.googleapis.com"}</li>
83
   *   <li>{@code "dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"}</li>
84
   *   <li>{@code "dns://8.8.8.8/foo.googleapis.com:8080"}</li>
85
   *   <li>{@code "dns://8.8.8.8/foo.googleapis.com"}</li>
86
   *   <li>{@code "zookeeper://zk.example.com:9900/example_service"}</li>
87
   *   <li>{@code "intent:#Intent;package=com.some.app;action=a;category=c;end;"}</li>
88
   * </ul>
89
   *
90
   * <p>An authority string will be converted to a URI having the scheme of the name resolver with
91
   * the highest priority (e.g. {@code "dns"}), the empty string as the authority, and
92
   * {@code target} as its absolute path. We recommend libraries specify {@code target} as a URI
93
   * instead since they cannot know which NameResolver will be default at runtime.
94
   * Example authority strings:
95
   * <ul>
96
   *   <li>{@code "localhost"}</li>
97
   *   <li>{@code "127.0.0.1"}</li>
98
   *   <li>{@code "localhost:8080"}</li>
99
   *   <li>{@code "foo.googleapis.com:8080"}</li>
100
   *   <li>{@code "127.0.0.1:8080"}</li>
101
   *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]"}</li>
102
   *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"}</li>
103
   * </ul>
104
   *
105
   * <p>The URI form of {@code target} is preferred because it is less ambiguous. For example, the
106
   * target string {@code foo:8080} is a valid authority string with host {@code foo} and port
107
   * {@code 8080} but it is also a valid RFC 3986 URI with scheme {@code foo} and path {@code 8080}.
108
   * gRPC prioritizes the URI form, which means {@code foo:8080} will be treated as a URI with
109
   * scheme {@code foo}. Using {@code dns:///foo:8080} avoids this ambiguity.
110
   */
111
  public static ManagedChannelBuilder<?> newChannelBuilder(
112
      String target, ChannelCredentials creds) {
113
    return ManagedChannelRegistry.getDefaultRegistry().newChannelBuilder(target, creds);
1✔
114
  }
115

116
  /**
117
   * Creates a channel builder with a target string, credentials, and a specific
118
   * name resolver registry.
119
   *
120
   * <p>The provided {@code nameResolverRegistry} is used to resolve the target address
121
   * into physical addresses (e.g., DNS or custom schemes).
122
   *
123
   * @param target the target URI for the channel, such as {@code "localhost:8080"}
124
   *     or {@code "dns:///example.com"}
125
   * @param creds the channel credentials to use for secure communication
126
   * @param nameResolverRegistry the registry used to look up {@link NameResolver}
127
   *     providers for the target
128
   * @return a {@link ManagedChannelBuilder} instance configured with the given parameters
129
   * @throws IllegalArgumentException if no provider is available for the given target
130
   *     or credentials
131
   * @since 1.83.0
132
   */
133
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12694")
134
  public static ManagedChannelBuilder<?> newChannelBuilder(
135
      String target,
136
      ChannelCredentials creds,
137
      NameResolverRegistry nameResolverRegistry) {
138
    return ManagedChannelRegistry.getDefaultRegistry().newChannelBuilder(
×
139
        nameResolverRegistry,
140
        target,
141
        creds);
142
  }
143

144
  /**
145
   * Creates a channel builder from a host, port, and credentials. The host and port are combined to
146
   * form an authority string and then passed to {@link #newChannelBuilder(String,
147
   * ChannelCredentials)}. IPv6 addresses are properly surrounded by square brackets ("[]").
148
   */
149
  public static ManagedChannelBuilder<?> newChannelBuilderForAddress(
150
      String host, int port, ChannelCredentials creds) {
151
    return newChannelBuilder(authorityFromHostAndPort(host, port), creds);
1✔
152
  }
153

154
  /**
155
   * Combine a host and port into an authority string.
156
   */
157
  // A copy of GrpcUtil.authorityFromHostAndPort
158
  private static String authorityFromHostAndPort(String host, int port) {
159
    try {
160
      return new URI(null, null, host, port, null, null, null).getAuthority();
1✔
161
    } catch (URISyntaxException ex) {
×
162
      throw new IllegalArgumentException("Invalid host or port: " + host + " " + port, ex);
×
163
    }
164
  }
165

166
  /**
167
   * Static factory for creating a new ServerBuilder.
168
   *
169
   * @param port the port to listen on
170
   * @param creds the server identity
171
   */
172
  public static ServerBuilder<?> newServerBuilderForPort(int port, ServerCredentials creds) {
173
    return ServerRegistry.getDefaultRegistry().newServerBuilderForPort(port, creds);
1✔
174
  }
175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc