Skip to content

Commit

Permalink
Ignore ClosedByInterruptExceptions (better fix for #19)
Browse files Browse the repository at this point in the history
The thread stays interrupted after catching the exception, so retrying is
pointless
  • Loading branch information
makamys committed Oct 27, 2023
1 parent bb680f2 commit 62505db
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ private static Map<String, TransformerData> returnVerifiedTransformerMap(Map<Str
@Override
public void onShutdown() {
try {
if(CachedTransformation.diffErrors > 0) {
logger().warn(CachedTransformation.diffErrors + " entries have errored. Please report this if it keeps happening!");
}
saveTransformerCache();
saveProfilingResults();
} catch (IOException e) {
Expand Down Expand Up @@ -348,6 +351,8 @@ public TransformerData() {}
public static class CachedTransformation {
private static final byte[] INVALID_RESULT = new byte[] {};

static int diffErrors = 0;

String targetClassName;
int preLength;
int preHash;
Expand Down Expand Up @@ -379,23 +384,20 @@ private static byte[] generateDiff(byte[] source, int sourceLen, byte[] target,
return target;
}

for(int attemptsLeft = 4; attemptsLeft >= 0; attemptsLeft--) {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
delta.compute(new FastByteBufferSeekableSource(ByteBuffer.wrap(source, 0, sourceLen)), new ByteArrayInputStream(target), new GDiffWriter(os));
return os.toByteArray();
} catch(Exception e) {
if(!(e instanceof ClosedByInterruptException)) {
attemptsLeft = 0;
}
if(attemptsLeft > 0) {
LOGGER.error("Failed to generate diff for class " + name + ", will try again " + attemptsLeft + " more times");
} else {
LOGGER.error("Failed to generate diff for class " + name + ". Please report this if it keeps happening!");
}
e.printStackTrace();
}
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
delta.compute(new FastByteBufferSeekableSource(ByteBuffer.wrap(source, 0, sourceLen)), new ByteArrayInputStream(target), new GDiffWriter(os));
return os.toByteArray();
} catch(ClosedByInterruptException e) {
// nothome delta library uses interruptible channels which throw an error if the thread gets interrupted.
// No big deal, it's a race condition so it probably won't happen next time.
LOGGER.debug("Failed to generate diff for class " + name + ", thread was interrupted.");
} catch(Exception e) {
// Unknown exception. We want to know more about this, but it's not worth crashing over if it's a rare issue.
LOGGER.error("Failed to generate diff for class " + name + ". Please report this if it keeps happening!");
e.printStackTrace();
}
diffErrors++;
return INVALID_RESULT;
}

Expand Down

0 comments on commit 62505db

Please sign in to comment.