Skip to content

Commit 5f6d5de

Browse files
committed
Don't lock the scope multiple times
This lead to a situation where unlocking wouldn't properly unlock it
1 parent 232c15d commit 5f6d5de

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

platform_api/src/main/java/net/modfest/platform/git/GitScopeManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ void runWithScopedGit(GitFunction r) {
7070
setScope(new GitScope("PLATFORM CHANGE"));
7171
}
7272
try {
73-
if (!scopeLock.tryLock(10, TimeUnit.SECONDS)) {
74-
// This is a pretty serious error condition which should not be happening
75-
// so I'm okay with doing some dirty hacks as long as we get the debug information to fix this
76-
var owner = scopeLock.getOwner();
77-
var scope = ThreadLocalHack.getValueOfOtherThread(gitScopes, owner);
78-
LOGGER.error("Platform failed to obtain git lock. We're blocked on {} and waiting for it to commit: {}", owner, scope);
79-
throw new RuntimeException("Major timeout error. Waiting on a change to be committed to git before we can start writing.");
73+
if (!this.scopeLock.isHeldByCurrentThread()) {
74+
if (!scopeLock.tryLock(10, TimeUnit.SECONDS)) {
75+
// This is a pretty serious error condition which should not be happening
76+
// so I'm okay with doing some dirty hacks as long as we get the debug information to fix this
77+
var owner = scopeLock.getOwner();
78+
var scope = ThreadLocalHack.getValueOfOtherThread(gitScopes, owner);
79+
LOGGER.error("Platform failed to obtain git lock. We're blocked on {} and waiting for it to commit: {}", owner, scope);
80+
throw new RuntimeException("Major timeout error. Waiting on a change to be committed to git before we can start writing.");
81+
}
8082
}
8183
// The lock is now owned by this thread, which means that our
8284
// thread scope is the active scope.

0 commit comments

Comments
 (0)