Skip to content

Commit

Permalink
More broad catching
Browse files Browse the repository at this point in the history
  • Loading branch information
carterkozak committed Aug 28, 2017
1 parent 76f5335 commit 32bfc58
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 44 deletions.
Expand Up @@ -101,7 +101,8 @@ public void handleEvent(StreamSourceChannel channel) {
fallback.handleEvent(sslConnection); fallback.handleEvent(sslConnection);
return; return;
} }
} catch (IOException e) { } catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
failedListener.failed(e); failedListener.failed(e);
} }
} }
Expand Down
Expand Up @@ -271,8 +271,8 @@ private void initiateRequest(AjpClientExchange AjpClientExchange) {
if (!sinkChannel.flush()) { if (!sinkChannel.flush()) {
handleFailedFlush(sinkChannel); handleFailedFlush(sinkChannel);
} }
} catch (IOException e) { } catch (Throwable t) {
handleError(e); handleError((t instanceof IOException) ? (IOException) t : new IOException(t));
} }
} }
} }
Expand Down Expand Up @@ -358,7 +358,7 @@ public void handleEvent(AjpClientChannel channel) {
Channels.drain(result, Long.MAX_VALUE); Channels.drain(result, Long.MAX_VALUE);
} }


} catch (Exception e) { } catch (Throwable e) {
UndertowLogger.CLIENT_LOGGER.exceptionProcessingRequest(e); UndertowLogger.CLIENT_LOGGER.exceptionProcessingRequest(e);
safeClose(connection); safeClose(connection);
if(currentRequest != null) { if(currentRequest != null) {
Expand Down
Expand Up @@ -149,8 +149,8 @@ public void handleEvent(SslConnection connection) {
if(connection instanceof SslConnection) { if(connection instanceof SslConnection) {
try { try {
((SslConnection) connection).startHandshake(); ((SslConnection) connection).startHandshake();
} catch (IOException e) { } catch (Throwable t) {
listener.failed(e); listener.failed((t instanceof IOException) ? (IOException) t : new IOException(t));
} }
} }
listener.completed(new HttpClientConnection(connection, options, bufferPool)); listener.completed(new HttpClientConnection(connection, options, bufferPool));
Expand Down
Expand Up @@ -530,7 +530,7 @@ public int write(final ByteBuffer src) throws IOException {
return next.write(src) + alreadyWritten; return next.write(src) + alreadyWritten;
} }
return alreadyWritten; return alreadyWritten;
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
this.state |= FLAG_SHUTDOWN; this.state |= FLAG_SHUTDOWN;
if(pooledBuffer != null) { if(pooledBuffer != null) {
pooledBuffer.close(); pooledBuffer.close();
Expand Down Expand Up @@ -566,7 +566,7 @@ public long write(final ByteBuffer[] srcs, final int offset, final int length) t
} }
} }
return length == 1 ? next.write(srcs[offset]) : next.write(srcs, offset, length); return length == 1 ? next.write(srcs[offset]) : next.write(srcs, offset, length);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
this.state |= FLAG_SHUTDOWN; this.state |= FLAG_SHUTDOWN;
if(pooledBuffer != null) { if(pooledBuffer != null) {
pooledBuffer.close(); pooledBuffer.close();
Expand Down Expand Up @@ -607,7 +607,7 @@ public long transferFrom(final FileChannel src, final long position, final long
} }
} }
return next.transferFrom(src, position, count); return next.transferFrom(src, position, count);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
this.state |= FLAG_SHUTDOWN; this.state |= FLAG_SHUTDOWN;
if(pooledBuffer != null) { if(pooledBuffer != null) {
pooledBuffer.close(); pooledBuffer.close();
Expand Down Expand Up @@ -639,7 +639,7 @@ public long transferFrom(final StreamSourceChannel source, final long count, fin
} }
} }
return next.transferFrom(source, count, throughBuffer); return next.transferFrom(source, count, throughBuffer);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
this.state |= FLAG_SHUTDOWN; this.state |= FLAG_SHUTDOWN;
if(pooledBuffer != null) { if(pooledBuffer != null) {
pooledBuffer.close(); pooledBuffer.close();
Expand Down Expand Up @@ -670,7 +670,7 @@ public boolean flush() throws IOException {
} }
log.trace("Delegating flush"); log.trace("Delegating flush");
return next.flush(); return next.flush();
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
this.state |= FLAG_SHUTDOWN; this.state |= FLAG_SHUTDOWN;
if(pooledBuffer != null) { if(pooledBuffer != null) {
pooledBuffer.close(); pooledBuffer.close();
Expand Down
Expand Up @@ -196,7 +196,8 @@ public void sendRequest(ClientRequest request, ClientCallback<ClientExchange> cl
Http2HeadersStreamSinkChannel sinkChannel; Http2HeadersStreamSinkChannel sinkChannel;
try { try {
sinkChannel = http2Channel.createStream(request.getRequestHeaders()); sinkChannel = http2Channel.createStream(request.getRequestHeaders());
} catch (IOException e) { } catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
clientCallback.failed(e); clientCallback.failed(e);
return; return;
} }
Expand Down Expand Up @@ -227,14 +228,14 @@ public void handleException(StreamSinkChannel channel, IOException exception) {
})); }));
sinkChannel.resumeWrites(); sinkChannel.resumeWrites();
} }
} catch (IOException e) { } catch (Throwable e) {
handleError(e); handleError(e);
} }
} }
} }


private void handleError(IOException e) { private void handleError(Throwable t) {

IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e); UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
IoUtils.safeClose(Http2ClientConnection.this); IoUtils.safeClose(Http2ClientConnection.this);
for (Map.Entry<Integer, Http2ClientExchange> entry : currentExchanges.entrySet()) { for (Map.Entry<Integer, Http2ClientExchange> entry : currentExchanges.entrySet()) {
Expand Down Expand Up @@ -448,13 +449,14 @@ public void handleEvent(Http2StreamSourceChannel channel) {
Channels.drain(result, Long.MAX_VALUE); Channels.drain(result, Long.MAX_VALUE);
} }


} catch (IOException e) { } catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e); UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
IoUtils.safeClose(Http2ClientConnection.this); IoUtils.safeClose(Http2ClientConnection.this);
for (Map.Entry<Integer, Http2ClientExchange> entry : currentExchanges.entrySet()) { for (Map.Entry<Integer, Http2ClientExchange> entry : currentExchanges.entrySet()) {
try { try {
entry.getValue().failed(e); entry.getValue().failed(e);
} catch (Exception ex) { } catch (Throwable ex) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(new IOException(ex)); UndertowLogger.REQUEST_IO_LOGGER.ioException(new IOException(ex));
} }
} }
Expand Down
Expand Up @@ -145,15 +145,17 @@ public void handleEvent(ConduitStreamSinkChannel channel) {
return; return;
} }
listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false)); listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false));
} catch (IOException e) { } catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
listener.failed(e); listener.failed(e);
} }
} }
}); });
return; return;
} }
listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false)); listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false));
} catch (IOException e) { } catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
listener.failed(e); listener.failed(e);
} }
} }
Expand Down
Expand Up @@ -104,7 +104,7 @@ public int write(final ByteBuffer src) throws IOException {
int res = 0; int res = 0;
try { try {
return res = next.write(src); return res = next.write(src);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} finally { } finally {
Expand Down Expand Up @@ -146,7 +146,7 @@ public long write(final ByteBuffer[] srcs, final int offset, final int length) t
long res = 0L; long res = 0L;
try { try {
return res = next.write(srcs, offset, length); return res = next.write(srcs, offset, length);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} finally { } finally {
Expand All @@ -163,7 +163,7 @@ public long write(final ByteBuffer[] srcs, final int offset, final int length) t
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException {
try { try {
return Conduits.writeFinalBasic(this, srcs, offset, length); return Conduits.writeFinalBasic(this, srcs, offset, length);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} }
Expand All @@ -173,7 +173,7 @@ public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOExcep
public int writeFinal(ByteBuffer src) throws IOException { public int writeFinal(ByteBuffer src) throws IOException {
try { try {
return Conduits.writeFinalBasic(this, src); return Conduits.writeFinalBasic(this, src);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} }
Expand All @@ -191,7 +191,7 @@ public long transferFrom(final FileChannel src, final long position, final long
long res = 0L; long res = 0L;
try { try {
return res = next.transferFrom(src, position, min(count, (val & MASK_COUNT))); return res = next.transferFrom(src, position, min(count, (val & MASK_COUNT)));
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} finally { } finally {
Expand All @@ -211,7 +211,7 @@ public long transferFrom(final StreamSourceChannel source, final long count, fin
long res = 0L; long res = 0L;
try { try {
return res = next.transferFrom(source, min(count, (val & MASK_COUNT)), throughBuffer); return res = next.transferFrom(source, min(count, (val & MASK_COUNT)), throughBuffer);
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} finally { } finally {
Expand All @@ -227,7 +227,7 @@ public boolean flush() throws IOException {
boolean flushed = false; boolean flushed = false;
try { try {
return flushed = next.flush(); return flushed = next.flush();
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
broken = true; broken = true;
throw e; throw e;
} finally { } finally {
Expand Down
Expand Up @@ -161,13 +161,14 @@ private long doWrite(ByteBuffer[] additionalData, int offs, int len) throws IOEx
} }
return toAllocate; return toAllocate;


} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
IOException ioe = e instanceof IOException ? (IOException) e : new IOException(e);
//on exception we fail every item in the frame queue //on exception we fail every item in the frame queue
try { try {
for (Frame frame : frameQueue) { for (Frame frame : frameQueue) {
FrameCallBack cb = frame.callback; FrameCallBack cb = frame.callback;
if (cb != null) { if (cb != null) {
cb.failed(e); cb.failed(ioe);
} }
} }
frameQueue.clear(); frameQueue.clear();
Expand Down
Expand Up @@ -19,6 +19,8 @@
package io.undertow.conduits; package io.undertow.conduits;


import io.undertow.UndertowMessages; import io.undertow.UndertowMessages;
import io.undertow.connector.ByteBufferPool;
import io.undertow.connector.PooledByteBuffer;
import io.undertow.server.Connectors; import io.undertow.server.Connectors;
import io.undertow.server.HttpServerExchange; import io.undertow.server.HttpServerExchange;
import io.undertow.server.protocol.http.HttpAttachments; import io.undertow.server.protocol.http.HttpAttachments;
Expand All @@ -28,8 +30,6 @@
import io.undertow.util.HeaderMap; import io.undertow.util.HeaderMap;
import io.undertow.util.PooledAdaptor; import io.undertow.util.PooledAdaptor;
import org.xnio.IoUtils; import org.xnio.IoUtils;
import io.undertow.connector.ByteBufferPool;
import io.undertow.connector.PooledByteBuffer;
import org.xnio.channels.StreamSinkChannel; import org.xnio.channels.StreamSinkChannel;
import org.xnio.conduits.AbstractStreamSourceConduit; import org.xnio.conduits.AbstractStreamSourceConduit;
import org.xnio.conduits.ConduitReadableByteChannel; import org.xnio.conduits.ConduitReadableByteChannel;
Expand Down Expand Up @@ -107,7 +107,7 @@ protected ChunkedStreamSourceConduit(final StreamSourceConduit next, final Buffe
public long transferTo(final long position, final long count, final FileChannel target) throws IOException { public long transferTo(final long position, final long count, final FileChannel target) throws IOException {
try { try {
return target.transferFrom(new ConduitReadableByteChannel(this), position, count); return target.transferFrom(new ConduitReadableByteChannel(this), position, count);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(closeable); IoUtils.safeClose(closeable);
throw e; throw e;
} }
Expand Down Expand Up @@ -140,7 +140,7 @@ private void updateRemainingAllowed(final int written) throws IOException {
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException {
try { try {
return IoUtils.transfer(new ConduitReadableByteChannel(this), count, throughBuffer, target); return IoUtils.transfer(new ConduitReadableByteChannel(this), count, throughBuffer, target);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(closeable); IoUtils.safeClose(closeable);
throw e; throw e;
} }
Expand Down Expand Up @@ -281,7 +281,7 @@ public int read(final ByteBuffer dst) throws IOException {
pooled.close(); pooled.close();
} }
} }
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(closeable); IoUtils.safeClose(closeable);
throw e; throw e;
} finally { } finally {
Expand Down
Expand Up @@ -136,7 +136,7 @@ public int write(final ByteBuffer src) throws IOException {
Connectors.updateResponseBytesSent(exchange, 0 - data.length); Connectors.updateResponseBytesSent(exchange, 0 - data.length);
deflateData(false); deflateData(false);
return data.length; return data.length;
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
freeBuffer(); freeBuffer();
throw e; throw e;
} }
Expand All @@ -163,7 +163,7 @@ public long write(final ByteBuffer[] srcs, final int offset, final int length) t
} }
} }
return total; return total;
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
freeBuffer(); freeBuffer();
throw e; throw e;
} }
Expand Down Expand Up @@ -400,13 +400,13 @@ public boolean flush() throws IOException {
if (anyAreSet(state, WRITES_RESUMED) && !anyAreSet(state ,NEXT_SHUTDOWN)) { if (anyAreSet(state, WRITES_RESUMED) && !anyAreSet(state ,NEXT_SHUTDOWN)) {
try { try {
next.resumeWrites(); next.resumeWrites();
} catch (Exception e) { } catch (Throwable e) {
UndertowLogger.REQUEST_LOGGER.debug("Failed to resume", e); UndertowLogger.REQUEST_LOGGER.debug("Failed to resume", e);
} }
} }
} }
} }
} catch (IOException e) { } catch (IOException | RuntimeException | Error e) {
freeBuffer(); freeBuffer();
throw e; throw e;
} }
Expand Down
Expand Up @@ -123,7 +123,7 @@ public long transferTo(final long position, final long count, final FileChannel
long res = 0L; long res = 0L;
try { try {
return res = next.transferTo(position, min(count, val & MASK_COUNT), target); return res = next.transferTo(position, min(count, val & MASK_COUNT), target);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} finally { } finally {
Expand All @@ -146,7 +146,7 @@ public long transferTo(final long count, final ByteBuffer throughBuffer, final S
long res = 0L; long res = 0L;
try { try {
return res = next.transferTo(min(count, val & MASK_COUNT), throughBuffer, target); return res = next.transferTo(min(count, val & MASK_COUNT), throughBuffer, target);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} finally { } finally {
Expand Down Expand Up @@ -212,7 +212,7 @@ public long read(final ByteBuffer[] dsts, final int offset, final int length) th
} }
// the total buffer space is less than the remaining count. // the total buffer space is less than the remaining count.
return res = next.read(dsts, offset, length); return res = next.read(dsts, offset, length);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} finally { } finally {
Expand Down Expand Up @@ -248,7 +248,7 @@ public int read(final ByteBuffer dst) throws IOException {
} else { } else {
return res = next.read(dst); return res = next.read(dst);
} }
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} finally { } finally {
Expand Down Expand Up @@ -292,7 +292,7 @@ public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOExc
} }
try { try {
next.awaitReadable(time, timeUnit); next.awaitReadable(time, timeUnit);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} }
Expand Down
Expand Up @@ -199,7 +199,7 @@ private void done() {
public long transferTo(final long position, final long count, final FileChannel target) throws IOException { public long transferTo(final long position, final long count, final FileChannel target) throws IOException {
try { try {
return target.transferFrom(new ConduitReadableByteChannel(this), position, count); return target.transferFrom(new ConduitReadableByteChannel(this), position, count);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} }
Expand All @@ -209,7 +209,7 @@ public long transferTo(final long position, final long count, final FileChannel
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException {
try { try {
return IoUtils.transfer(new ConduitReadableByteChannel(this), count, throughBuffer, target); return IoUtils.transfer(new ConduitReadableByteChannel(this), count, throughBuffer, target);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection()); IoUtils.safeClose(exchange.getConnection());
throw e; throw e;
} }
Expand Down

0 comments on commit 32bfc58

Please sign in to comment.