Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2016-07-07 14:57:49 +0000
committerMatthias Sohn2016-07-12 09:32:50 +0000
commitceaadf8f9835e01ca8b361885ea357d7b00536b6 (patch)
treee9c13875315e95ffaead93e9bb41956e6c6770b4
parent7ffe547da79bf26301c5e5a0665d19a233b44818 (diff)
downloadjgit-ceaadf8f9835e01ca8b361885ea357d7b00536b6.tar.gz
jgit-ceaadf8f9835e01ca8b361885ea357d7b00536b6.tar.xz
jgit-ceaadf8f9835e01ca8b361885ea357d7b00536b6.zip
Log if Repository.useCnt becomes negative
We observe in Gerrit 2.12 that useCnt can become negative in rare cases. Log this to help finding the bug. Change-Id: Ie91c7f9d190a5d7cf4733d4bf84124d119ca20f7 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java18
3 files changed, 19 insertions, 1 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
index 83a72f0d5b..21fbaa4918 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -185,6 +185,7 @@ corruptObjectTruncatedInMode=truncated in mode
corruptObjectTruncatedInName=truncated in name
corruptObjectTruncatedInObjectId=truncated in object id
corruptObjectZeroId=entry points to null SHA-1
+corruptUseCnt=close() called when useCnt is already zero
couldNotCheckOutBecauseOfConflicts=Could not check out because of conflicts
couldNotDeleteLockFileShouldNotHappen=Could not delete lock file. Should not happen
couldNotDeleteTemporaryIndexFileShouldNotHappen=Could not delete temporary index file. Should not happen
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
index 99b18b72cc..b7ef0854c9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -245,6 +245,7 @@ public class JGitText extends TranslationBundle {
/***/ public String corruptObjectTruncatedInObjectId;
/***/ public String corruptObjectZeroId;
/***/ public String corruptPack;
+ /***/ public String corruptUseCnt;
/***/ public String couldNotCheckOutBecauseOfConflicts;
/***/ public String couldNotDeleteLockFileShouldNotHappen;
/***/ public String couldNotDeleteTemporaryIndexFileShouldNotHappen;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 9711fda5cc..7ec24998b4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -94,6 +94,8 @@ import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.SystemReader;
import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Represents a Git repository.
@@ -104,6 +106,8 @@ import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
* This class is thread-safe.
*/
public abstract class Repository implements AutoCloseable {
+ private static Logger LOG = LoggerFactory.getLogger(Repository.class);
+
private static final ListenerList globalListeners = new ListenerList();
/** @return the global listener list observing all events in this JVM. */
@@ -866,12 +870,24 @@ public abstract class Repository implements AutoCloseable {
/** Decrement the use count, and maybe close resources. */
public void close() {
- if (useCnt.decrementAndGet() == 0) {
+ int newCount = useCnt.decrementAndGet();
+ if (newCount == 0) {
if (RepositoryCache.isCached(this)) {
closedAt.set(System.currentTimeMillis());
} else {
doClose();
}
+ } else if (newCount == -1) {
+ // should not happen, only log when useCnt became negative to
+ // minimize number of log entries
+ LOG.warn(JGitText.get().corruptUseCnt);
+ if (LOG.isDebugEnabled()) {
+ IllegalStateException e = new IllegalStateException();
+ LOG.debug("", e); //$NON-NLS-1$
+ }
+ if (RepositoryCache.isCached(this)) {
+ closedAt.set(System.currentTimeMillis());
+ }
}
}

Back to the top