Browse Source

Don't invalidate pack file on InterruptedIOException

If the thread reading a pack file is interrupted don't invalidate that
pack file.

This could happen when Gerrit invoked JGit for computing a diff in one
thread and waited for the call to finish from another thread, with a
timeout. When the timeout was reached the "diff" thread was interrupted.
If it happened to be in an IO operation, reading a pack file, an
InterruptedIOException was thrown and the pack file was marked as
invalid and removed from the pack list.

Invalidating the pack in that case could cause the project disappearing in
Gerrit as discussed in [1] and [2].

[1] https://groups.google.com/forum/#!topic/repo-discuss/CYYoHfDxCfA
[2] https://groups.google.com/forum/#!topic/repo-discuss/ZeGWPyyJlrM

Change-Id: I2eb1f98370936b5be541d96d70c3973cbfc39238
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
stable-4.1
Saša Živkov 10 years ago committed by Matthias Sohn
parent
commit
d9062145b8
  1. 18
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

18
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

@ -51,6 +51,7 @@ import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer; import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel.MapMode; import java.nio.channels.FileChannel.MapMode;
@ -177,6 +178,9 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
packFile.getPath())); packFile.getPath()));
} }
loadedIdx = idx; loadedIdx = idx;
} catch (InterruptedIOException e) {
// don't invalidate the pack, we are interrupted from another thread
throw e;
} catch (IOException e) { } catch (IOException e) {
invalid = true; invalid = true;
throw e; throw e;
@ -605,22 +609,26 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
length = fd.length(); length = fd.length();
onOpenPack(); onOpenPack();
} }
} catch (InterruptedIOException e) {
// don't invalidate the pack, we are interrupted from another thread
openFail(false);
throw e;
} catch (IOException ioe) { } catch (IOException ioe) {
openFail(); openFail(true);
throw ioe; throw ioe;
} catch (RuntimeException re) { } catch (RuntimeException re) {
openFail(); openFail(true);
throw re; throw re;
} catch (Error re) { } catch (Error re) {
openFail(); openFail(true);
throw re; throw re;
} }
} }
private void openFail() { private void openFail(boolean invalidate) {
activeWindows = 0; activeWindows = 0;
activeCopyRawData = 0; activeCopyRawData = 0;
invalid = true; invalid = invalidate;
doClose(); doClose();
} }

Loading…
Cancel
Save