From 2447009f9967d73461a4ee26e24f8d1f824d16aa Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 9 Nov 2021 09:02:01 +0100 Subject: [PATCH 1/3] fixed potential DB deadlock cause --- .../session/impl/indicator/DistributedPingCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java index e35bbdf5..5d170162 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java @@ -180,7 +180,7 @@ public class DistributedPingCache implements DisposableBean { } } - @Transactional + @Transactional(readOnly = true) public void updateCache() { if (this.pingCache.isEmpty()) { From a747c484584ebf2c4190dae80477ec4262ce583d Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 9 Nov 2021 09:07:26 +0100 Subject: [PATCH 2/3] fixed tests --- .../integration/api/admin/ExamProctoringRoomServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamProctoringRoomServiceTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamProctoringRoomServiceTest.java index b13bc549..9c1874c6 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamProctoringRoomServiceTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamProctoringRoomServiceTest.java @@ -51,7 +51,8 @@ public class ExamProctoringRoomServiceTest extends AdministrationAPIIntegrationT assertFalse(runningExamsForInstitution.hasError()); final Collection collection = runningExamsForInstitution.get(); assertFalse(collection.isEmpty()); - final Exam exam = collection.iterator().next(); + final Exam exam = collection.stream().filter(e -> e.id == 2L).findAny().orElse(null); + assertNotNull(exam); assertEquals("Demo Quiz 6 (MOCKUP)", exam.name); assertEquals("2", String.valueOf(exam.id)); } From 780a17834c35c143a9cb3a57f3f797ac07f338f3 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 9 Nov 2021 09:39:11 +0100 Subject: [PATCH 3/3] more fixes to prevent DB deadlocks --- .../session/impl/indicator/AbstractPingIndicator.java | 4 +++- .../session/impl/indicator/DistributedPingCache.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractPingIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractPingIndicator.java index 553d972d..a67a7546 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractPingIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractPingIndicator.java @@ -77,7 +77,9 @@ public abstract class AbstractPingIndicator extends AbstractClientIndicator { // Update last ping time on persistent storage final long millisecondsNow = DateTimeUtils.currentTimeMillis(); if (millisecondsNow - this.lastUpdate > INTERVAL_FOR_PERSISTENT_UPDATE) { - this.distributedPingCache.updatePing(this.pingRecord, millisecondsNow); + synchronized (this) { + this.distributedPingCache.updatePing(this.pingRecord, millisecondsNow); + } } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java index 5d170162..979df7fa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/DistributedPingCache.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.TaskScheduler; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import ch.ethz.seb.sebserver.gbl.model.session.ClientEvent.EventType; @@ -180,7 +181,7 @@ public class DistributedPingCache implements DisposableBean { } } - @Transactional(readOnly = true) + @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public void updateCache() { if (this.pingCache.isEmpty()) {