Skip to content

Commit

Permalink
GEODE-9867: do not process the message if the connection is terminated (
Browse files Browse the repository at this point in the history
  • Loading branch information
jinmeiliao authored Dec 6, 2021
1 parent 7179a7c commit 99bbf99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ public static Byte isExecuteFunctionOnLocalNodeOnly() {
return executeFunctionOnLocalNodeOnly.get();
}

@VisibleForTesting
void setServerConnectionCollection(
ServerConnectionCollection serverConnectionCollection) {
this.serverConnectionCollection = serverConnectionCollection;
}

private boolean verifyClientConnection() {
synchronized (handshakeMonitor) {
if (handshake == null) {
Expand Down Expand Up @@ -816,6 +822,12 @@ void doNormalMessage() {
return;
}

if (isTerminated()) {
// Client is being terminated, don't try to process message.
processMessages = false;
return;
}

ThreadState threadState = null;
resumeThreadMonitoring();
try {
Expand Down Expand Up @@ -930,7 +942,8 @@ private void suspendThreadMonitoring() {
}
}

private void resumeThreadMonitoring() {
@VisibleForTesting
void resumeThreadMonitoring() {
if (threadMonitorExecutor != null) {
threadMonitorExecutor.resumeMonitoring();
}
Expand Down Expand Up @@ -966,6 +979,7 @@ void handleTermination(boolean timedOut) {
}
terminated = true;
}

setNotProcessingMessage();
boolean clientDeparted = false;
boolean cleanupStats = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,18 @@ public void getUniqueIdBytesShouldThrowCacheClosedException() throws Exception {
assertThatThrownBy(() -> spy.getUniqueIdBytes(requestMessage, -1))
.isInstanceOf(CacheClosedException.class);
}

@Test
public void doNormalMessageShouldNotProcessMessageWhenTerminated() {
ServerConnection spy = spy(serverConnection);
ServerConnectionCollection serverConnections = mock(ServerConnectionCollection.class);
spy.setServerConnectionCollection(serverConnections);
when(serverConnections.incrementConnectionsProcessing()).thenReturn(true);

doReturn(true).when(spy).isTerminated();

spy.doNormalMessage();
assertThat(spy.getProcessMessages()).isFalse();
verify(spy, never()).resumeThreadMonitoring();
}
}

0 comments on commit 99bbf99

Please sign in to comment.