Skip to content

Commit

Permalink
log cleaner error message when broken pipe occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jun 1, 2012
1 parent 8d4021c commit 8eaca21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Expand Up @@ -134,5 +134,13 @@ protected void close(ISqlTransaction transaction) {
transaction.close();
}
}

protected String getRootMessage(Exception ex) {
Throwable cause = ExceptionUtils.getRootCause(ex);
if (cause == null) {
cause = ex;
}
return cause.getMessage();
}

}
Expand Up @@ -20,6 +20,7 @@
*/
package org.jumpmind.symmetric.service.impl;

import java.io.EOFException;
import java.io.OutputStream;
import java.io.Writer;
import java.sql.SQLException;
Expand All @@ -31,6 +32,7 @@
import java.util.concurrent.Semaphore;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.sql.ISqlReadCursor;
import org.jumpmind.db.sql.ISqlRowMapper;
Expand Down Expand Up @@ -357,7 +359,7 @@ public void extract(Node targetNode, IOutgoingTransport targetTransport,
}
}

} catch (Exception e) {
} catch (RuntimeException e) {
SQLException se = unwrapSqlException(e);
if (currentBatch != null) {
statisticManager.incrementDataExtractedErrors(currentBatch.getChannelId(), 1);
Expand All @@ -366,27 +368,35 @@ public void extract(Node targetNode, IOutgoingTransport targetTransport,
currentBatch.setSqlCode(se.getErrorCode());
currentBatch.setSqlMessage(se.getMessage());
} else {
currentBatch.setSqlMessage(e.getMessage());
currentBatch.setSqlMessage(getRootMessage(e));
}
currentBatch.revertStatsOnError();
if (currentBatch.getStatus() != Status.IG) {
currentBatch.setStatus(Status.ER);
}
currentBatch.setErrorFlag(true);
outgoingBatchService.updateOutgoingBatch(currentBatch);

if (isStreamClosedByClient(e)) {
log.warn("Failed to extract batch {}. The stream was closed by the client. There is a good chance that a previously sent batch errored out and the stream was closed. The error was: {}", currentBatch, getRootMessage(e));
} else {
log.error("Failed to extract batch {}", currentBatch, e);
}
} else {
log.error("Could not log the outgoing batch status because the batch was null.", e);
}

if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
log.error("Could not log the outgoing batch status because the batch was null", e);
}

}

}

protected boolean isStreamClosedByClient(Exception ex) {
if (ExceptionUtils.indexOfType(ex, EOFException.class) >= 0) {
return true;
} else {
return false;
}
}

final protected void changeBatchStatus(Status status, OutgoingBatch currentBatch) {
if (currentBatch.getStatus() != Status.IG) {
Expand Down

0 comments on commit 8eaca21

Please sign in to comment.