diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientEventBatchService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientEventBatchService.java index 1a29bb0b..7a262eca 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientEventBatchService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientEventBatchService.java @@ -160,10 +160,16 @@ public class SEBClientEventBatchService { return eventData; } - System.out.println("******* storeNotifications: " + eventData); + ClientConnectionDataInternal clientConnection = null; + synchronized (ExamSessionCacheService.CLIENT_CONNECTION_CREATION_LOCK) { + clientConnection = this.examSessionCacheService + .getClientConnection(eventData.connectionToken); + } - final ClientConnectionDataInternal clientConnection = this.examSessionCacheService - .getClientConnection(eventData.connectionToken); + if (clientConnection == null) { + log.error("Failed to get ClientConnectionDataInternal for: {}", eventData.connectionToken); + return null; + } final Pair typeAndPlainText = ClientNotification.extractTypeAndPlainText(eventData.event.text); @@ -200,8 +206,12 @@ public class SEBClientEventBatchService { private ClientEventRecord toEventRecord(final EventData eventData) { try { - final ClientConnectionDataInternal clientConnection = this.examSessionCacheService - .getClientConnection(eventData.connectionToken); + + ClientConnectionDataInternal clientConnection = null; + synchronized (ExamSessionCacheService.CLIENT_CONNECTION_CREATION_LOCK) { + clientConnection = this.examSessionCacheService + .getClientConnection(eventData.connectionToken); + } if (clientConnection == null) { log.warn("Failed to retrieve ClientConnection for token {}. Skip this event", diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java index 815aad01..44a86a95 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SEBClientPingBatchService.java @@ -91,11 +91,16 @@ public class SEBClientPingBatchService { return; } - final ClientConnectionDataInternal activeClientConnection = this.examSessionCacheService - .getClientConnection(connectionToken); + ClientConnectionDataInternal activeClientConnection = null; + synchronized (ExamSessionCacheService.CLIENT_CONNECTION_CREATION_LOCK) { + activeClientConnection = this.examSessionCacheService + .getClientConnection(connectionToken); + } if (activeClientConnection != null) { activeClientConnection.notifyPing(timestamp); + } else { + log.error("Failed to get ClientConnectionDataInternal for: {}", connectionToken); } if (instructionConfirm != StringUtils.EMPTY) {