44
44
import java .net .InetAddress ;
45
45
import java .net .InetSocketAddress ;
46
46
import java .net .URI ;
47
+ import java .net .UnknownHostException ;
47
48
import java .util .ArrayList ;
48
49
import java .util .Arrays ;
49
50
import java .util .Collections ;
@@ -165,36 +166,32 @@ public void run() {
165
166
}
166
167
try {
167
168
InetSocketAddress destination = InetSocketAddress .createUnresolved (host , port );
168
- ProxyParameters maybeNullParams = proxyDetector .proxyFor (destination );
169
+ ProxyParameters proxyParams = proxyDetector .proxyFor (destination );
169
170
Attributes attrs = Attributes .newBuilder ()
170
- .set (ProxyDetector .ATTR_KEY_PROXY_PARAMS , maybeNullParams )
171
+ .set (ProxyDetector .ATTR_KEY_PROXY_PARAMS , proxyParams )
171
172
.build ();
172
173
173
- ResolutionResults resolvedInetAddrs ;
174
+ ResolutionResults resolvedInetAddrs = null ;
174
175
try {
175
176
resolvedInetAddrs = delegateResolver .resolve (host );
176
- } catch (Exception e ) {
177
- synchronized (DnsNameResolver .this ) {
178
- if (shutdown ) {
179
- return ;
180
- }
181
- // Because timerService is the single-threaded GrpcUtil.TIMER_SERVICE in production,
182
- // we need to delegate the blocking work to the executor
183
- resolutionTask =
184
- timerService .schedule (new LogExceptionRunnable (resolutionRunnableOnExecutor ),
185
- 1 , TimeUnit .MINUTES );
177
+ } catch (UnknownHostException e ) {
178
+ // It is OK for a host to be unresolvable, assuming the proxy can resolve it
179
+ if (proxyParams == null ) {
180
+ handleError (savedListener , e );
181
+ return ;
186
182
}
187
- savedListener .onError (Status .UNAVAILABLE .withCause (e ));
183
+ } catch (Exception e ) {
184
+ handleError (savedListener , e );
188
185
return ;
189
186
}
190
187
ArrayList <EquivalentAddressGroup > servers = new ArrayList <EquivalentAddressGroup >();
191
- if (resolvedInetAddrs .addresses .isEmpty ()) {
192
- servers .add (new EquivalentAddressGroup (destination ));
193
- } else {
188
+ if (resolvedInetAddrs != null ) {
194
189
// Each address forms an EAG
195
190
for (InetAddress inetAddr : resolvedInetAddrs .addresses ) {
196
191
servers .add (new EquivalentAddressGroup (new InetSocketAddress (inetAddr , port ), attrs ));
197
192
}
193
+ } else {
194
+ servers .add (new EquivalentAddressGroup (destination , attrs ));
198
195
}
199
196
savedListener .onAddresses (servers , Attributes .EMPTY );
200
197
} finally {
@@ -205,6 +202,20 @@ public void run() {
205
202
}
206
203
};
207
204
205
+ private void handleError (Listener listener , Exception e ) {
206
+ synchronized (DnsNameResolver .this ) {
207
+ if (shutdown ) {
208
+ return ;
209
+ }
210
+ // Because timerService is the single-threaded GrpcUtil.TIMER_SERVICE in production,
211
+ // we need to delegate the blocking work to the executor
212
+ resolutionTask =
213
+ timerService .schedule (new LogExceptionRunnable (resolutionRunnableOnExecutor ),
214
+ 1 , TimeUnit .MINUTES );
215
+ }
216
+ listener .onError (Status .UNAVAILABLE .withCause (e ));
217
+ }
218
+
208
219
private final Runnable resolutionRunnableOnExecutor = new Runnable () {
209
220
@ Override
210
221
public void run () {
0 commit comments