final boolean failConnectPromise(Throwable cause) { if (connectPromise != null) { // SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was // not set before calling connect. This means finishConnect will not detect any error and would // successfully complete the connectPromise and update the channel state to active (which is incorrect). ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise; AbstractKQueueChannel.this.connectPromise = null; if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause : new ConnectException("failed to connect").initCause(cause))) { closeIfClosed(); return true; } } return false; }
final boolean failConnectPromise(Throwable cause) { if (connectPromise != null) { // SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was // not set before calling connect. This means finishConnect will not detect any error and would // successfully complete the connectPromise and update the channel state to active (which is incorrect). ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise; AbstractKQueueChannel.this.connectPromise = null; if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause : new ConnectException("failed to connect").initCause(cause))) { closeIfClosed(); return true; } } return false; }
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */ private void connectSocket(int connectTimeout, int readTimeout, Call call, EventListener eventListener) throws IOException { Proxy proxy = route.proxy(); Address address = route.address(); rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP ? address.socketFactory().createSocket() : new Socket(proxy); eventListener.connectStart(call, route.socketAddress(), proxy); rawSocket.setSoTimeout(readTimeout); try { Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout); } catch (ConnectException e) { ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress()); ce.initCause(e); throw ce; } // The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0 // More details: // https://github.com/square/okhttp/issues/3245 // https://android-review.googlesource.com/#/c/271775/ try { source = Okio.buffer(Okio.source(rawSocket)); sink = Okio.buffer(Okio.sink(rawSocket)); } catch (NullPointerException npe) { if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) { throw new IOException(npe); } } }
public void onFailure(Channel channel, Throwable cause) { // beware, channel can be null Channels.silentlyCloseChannel(channel); boolean canRetry = future.incrementRetryAndCheck(); LOGGER.debug("Trying to recover from failing to connect channel {} with a retry value of {} ", channel, canRetry); if (canRetry// && cause != null // FIXME when can we have a null cause? && (future.getChannelState() != ChannelState.NEW || StackTraceInspector.recoverOnNettyDisconnectException(cause))) { if (requestSender.retry(future)) { return; } } LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel); String message = cause.getMessage() != null ? cause.getMessage() : future.getUri().getBaseUrl(); ConnectException e = new ConnectException(message); e.initCause(cause); future.abort(e); } }
"Call to " + addr + " failed on connection exception: " + exception).initCause(exception); } else if (exception instanceof SocketTimeoutException) { return (SocketTimeoutException) new SocketTimeoutException(
c.initCause(e); } catch (SSLException e) { ConnectException c = new ConnectException("Problem connecting to peer " + addr); c.initCause(e); throw c; } catch (CancelledKeyException | ClosedSelectorException e) { String.format("Attempt timed out after %s milliseconds", connectTime)); c.initCause(e); throw c;
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */ private void connectSocket(int connectTimeout, int readTimeout, Call call, EventListener eventListener) throws IOException { Proxy proxy = route.proxy(); Address address = route.address(); rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP ? address.socketFactory().createSocket() : new Socket(proxy); eventListener.connectStart(call, route.socketAddress(), proxy); rawSocket.setSoTimeout(readTimeout); try { Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout); } catch (ConnectException e) { ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress()); ce.initCause(e); throw ce; } // The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0 // More details: // https://github.com/square/okhttp/issues/3245 // https://android-review.googlesource.com/#/c/271775/ try { source = Okio.buffer(Okio.source(rawSocket)); sink = Okio.buffer(Okio.sink(rawSocket)); } catch (NullPointerException npe) { if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) { throw new IOException(npe); } } }
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */ private void connectSocket(int connectTimeout, int readTimeout, Call call, EventListener eventListener) throws IOException { Proxy proxy = route.proxy(); Address address = route.address(); rawSocket = proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP ? address.socketFactory().createSocket() : new Socket(proxy); eventListener.connectStart(call, route.socketAddress(), proxy); rawSocket.setSoTimeout(readTimeout); try { Platform.get().connectSocket(rawSocket, route.socketAddress(), connectTimeout); } catch (ConnectException e) { ConnectException ce = new ConnectException("Failed to connect to " + route.socketAddress()); ce.initCause(e); throw ce; } // The following try/catch block is a pseudo hacky way to get around a crash on Android 7.0 // More details: // https://github.com/square/okhttp/issues/3245 // https://android-review.googlesource.com/#/c/271775/ try { source = Okio.buffer(Okio.source(rawSocket)); sink = Okio.buffer(Okio.sink(rawSocket)); } catch (NullPointerException npe) { if (NPE_THROW_WITH_NULL.equals(npe.getMessage())) { throw new IOException(npe); } } }
ex.initCause(cause); throw ex;
/** * Take a socket from the accept queue. * Only for subsession, throws IllegalStateException otherwise. * * @since 0.9.25 */ private I2PSocket acceptSocket() throws ConnectException { if (_acceptQueue == null) throw new IllegalStateException(); try { // TODO there's no CoDel or expiration in this queue return _acceptQueue.take(); } catch (InterruptedException ie) { ConnectException ce = new ConnectException("interrupted"); ce.initCause(ie); throw ce; } }
/** * Determine the proxy server (if any) needed to obtain a URL. * * @param proxySelector * proxy support for the caller. * @param u * location of the server caller wants to talk to. * @return proxy to communicate with the supplied URL. * @throws java.net.ConnectException * the proxy could not be computed as the supplied URL could not * be read. This failure should never occur. */ public static Proxy proxyFor(ProxySelector proxySelector, URL u) throws ConnectException { try { return proxySelector.select(u.toURI()).get(0); } catch (URISyntaxException e) { final ConnectException err; err = new ConnectException(MessageFormat.format(JGitText.get().cannotDetermineProxyFor, u)); err.initCause(e); throw err; } }
private void onFutureFailure(Channel channel, Throwable cause) { abortChannelPreemption(); boolean canRetry = future.canRetry(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Trying to recover from failing to connect channel " + channel + " with a retry value of " + canRetry, cause); } if (canRetry && cause != null && (future.getState() != NettyResponseFuture.STATE.NEW || StackTraceInspector.recoverOnDisconnectException(cause))) { if (requestSender.retry(future)) return; } LOGGER.debug("Failed to recover from connect exception: {} with channel {}", cause, channel); boolean printCause = cause != null && cause.getMessage() != null; String printedCause = printCause ? cause.getMessage() : getBaseUrl(future.getUri()); ConnectException e = new ConnectException(printedCause); if (cause != null) { e.initCause(cause); } future.abort(e); }
"Call to " + addr + " failed on connection exception: " + exception).initCause(exception); } else if (exception instanceof SocketTimeoutException) { return (SocketTimeoutException) new SocketTimeoutException(
public void finishConnect() throws IOException { try { channel.finishConnect(); } catch(ConnectException e) { ConnectException exc = new ConnectException("could not connect to="+isConnectingTo); exc.initCause(e); throw exc; } }
protected int invokeMethod(HttpMethodBase method) throws IOException { int result; try { result = httpClient.executeMethod(method); } catch (ConnectException e) { throw (ConnectException) new ConnectException( "Failed connecting to " + method.getURI() + ": " + e.getMessage()). initCause(e); } return result; }
final boolean failConnectPromise(Throwable cause) { if (connectPromise != null) { // SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was // not set before calling connect. This means finishConnect will not detect any error and would // successfully complete the connectPromise and update the channel state to active (which is incorrect). ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise; AbstractKQueueChannel.this.connectPromise = null; if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause : new ConnectException("failed to connect").initCause(cause))) { closeIfClosed(); return true; } } return false; }
final boolean failConnectPromise(Throwable cause) { if (connectPromise != null) { // SO_ERROR has been shown to return 0 on macOS if detect an error via read() and the write filter was // not set before calling connect. This means finishConnect will not detect any error and would // successfully complete the connectPromise and update the channel state to active (which is incorrect). ChannelPromise connectPromise = AbstractKQueueChannel.this.connectPromise; AbstractKQueueChannel.this.connectPromise = null; if (connectPromise.tryFailure((cause instanceof ConnectException) ? cause : new ConnectException("failed to connect").initCause(cause))) { closeIfClosed(); return true; } } return false; }
@Override public final ConnectException failedToConnect(final URI uri, final Exception cause) { final ConnectException result = new ConnectException(String.format(getLoggingLocale(), failedToConnect$str(), uri)); result.initCause(cause); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String channelClosed = "WFLYPRT0054: Channel closed";
@Override public final ConnectException failedToConnect(final URI uri, final Exception cause) { final ConnectException result = new ConnectException(String.format(getLoggingLocale(), failedToConnect$str(), uri)); result.initCause(cause); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String channelClosed = "WFLYPRT0054: Channel closed";