|
35 | 35 | import java.io.IOException;
|
36 | 36 | import java.io.InputStream;
|
37 | 37 | import java.io.RandomAccessFile;
|
| 38 | +import java.net.ConnectException; |
38 | 39 | import java.net.InetSocketAddress;
|
39 | 40 | import java.net.URI;
|
40 | 41 | import java.util.Map;
|
|
66 | 67 | import org.asynchttpclient.providers.netty4.future.NettyResponseFuture;
|
67 | 68 | import org.asynchttpclient.providers.netty4.future.NettyResponseFutures;
|
68 | 69 | import org.asynchttpclient.providers.netty4.request.FeedableBodyGenerator.FeedListener;
|
69 |
| -import org.asynchttpclient.providers.netty4.request.NettyConnectListener.Builder; |
70 | 70 | import org.asynchttpclient.util.AsyncHttpProviderUtils;
|
71 | 71 | import org.asynchttpclient.util.ProxyUtils;
|
72 | 72 | import org.asynchttpclient.websocket.WebSocketUpgradeHandler;
|
@@ -121,7 +121,7 @@ public boolean retry(Channel channel, NettyResponseFuture<?> future) {
|
121 | 121 | }
|
122 | 122 | return success;
|
123 | 123 | }
|
124 |
| - |
| 124 | + |
125 | 125 | public boolean applyIoExceptionFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture<?> future, IOException e) throws IOException {
|
126 | 126 |
|
127 | 127 | boolean replayed = false;
|
@@ -224,26 +224,35 @@ private void performSyncConnect(ChannelFuture channelFuture, URI uri, boolean ac
|
224 | 224 |
|
225 | 225 | try {
|
226 | 226 | channelFuture.syncUninterruptibly();
|
227 |
| - cl.onFutureSuccess(channelFuture.channel()); |
228 |
| - |
229 | 227 | } catch (Throwable t) {
|
230 | 228 | if (t.getCause() != null)
|
231 | 229 | t = t.getCause();
|
232 | 230 |
|
233 |
| - IOException ioe = null; |
234 |
| - if (t instanceof IOException) |
235 |
| - ioe = IOException.class.cast(t); |
| 231 | + ConnectException ce = null; |
| 232 | + if (t instanceof ConnectException) |
| 233 | + ce = ConnectException.class.cast(t); |
236 | 234 | else
|
237 |
| - ioe = new IOException(t.getMessage(), t); |
| 235 | + ce = new ConnectException(t.getMessage()); |
238 | 236 |
|
239 |
| - if (acquiredConnection) |
| 237 | + if (acquiredConnection) { |
240 | 238 | channels.releaseFreeConnections();
|
| 239 | + } |
| 240 | + channelFuture.cancel(false); |
| 241 | + channels.abort(cl.future(), ce); |
| 242 | + } |
241 | 243 |
|
242 |
| - channels.abort(cl.future(), ioe); |
| 244 | + try { |
| 245 | + cl.operationComplete(channelFuture); |
| 246 | + } catch (Exception e) { |
| 247 | + if (acquiredConnection) { |
| 248 | + channels.releaseFreeConnections(); |
| 249 | + } |
| 250 | + IOException ioe = new IOException(e.getMessage()); |
| 251 | + ioe.initCause(e); |
243 | 252 | try {
|
244 | 253 | asyncHandler.onThrowable(ioe);
|
245 |
| - } catch (Throwable t2) { |
246 |
| - LOGGER.warn("asyncHandler.onThrowable()", t2); |
| 254 | + } catch (Throwable t) { |
| 255 | + LOGGER.warn("c.operationComplete()", t); |
247 | 256 | }
|
248 | 257 | throw ioe;
|
249 | 258 | }
|
|
0 commit comments