-
Notifications
You must be signed in to change notification settings - Fork 53
[JCS-244] Fix the LateralTCPListener.handleClient to survive other exceptions #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd2912a
[JCS-244] Fix the LaterlatTCPListener.handleClient to survive also a …
orlat84 719c0d2
Update actions/cache version in coverage.yml
orlat84 489fc67
Update Maven CI workflow with new syntax
orlat84 0fbcb85
Testcase for the survival of LateralTCPListener after bad data
orlat84 c8ccc5a
Merge branch 'JCS-244-my-fix' of https://github.com/orlat84/commons-j…
orlat84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,9 +41,9 @@ jobs: | |
|
|
||
| steps: | ||
| - uses: actions/checkout@v3.5.2 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/cache@v3.3.1 | ||
| with: | ||
| persist-credentials: false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not edit this file.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified it, as some pipelines were failing and was getting notifications quite often on this |
||
| - uses: actions/cache@v3 | ||
| with: | ||
| path: ~/.m2/repository | ||
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
|
|
@@ -56,3 +56,4 @@ jobs: | |
| java-version: ${{ matrix.java }} | ||
| - name: Build with Maven | ||
| run: mvn -V --file pom.xml --no-transfer-progress -DtrimStackTrace=false | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...a/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListenerBadDataTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp; | ||
|
|
||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.io.ObjectOutputStream; | ||
| import java.net.Socket; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.commons.jcs3.JCS; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Test that a lateral TCP listener in a clustered setup survives receiving | ||
| * bad/corrupted data on its socket connection that triggers a | ||
| * {@link java.nio.BufferUnderflowException} during deserialization. | ||
| * <p> | ||
| * Without the fix, the listener thread dies upon encountering truncated | ||
| * serialized data because the {@code BufferUnderflowException} propagates | ||
| * out of the read loop. With the fix, the listener catches the exception, | ||
| * logs it, and continues processing subsequent valid messages. | ||
| * <p> | ||
| * This test sets up two lateral TCP cache nodes, sends the truncated data | ||
| * directly to one node's listener port, then verifies the listener is still | ||
| * alive. | ||
| */ | ||
| public class LateralTCPListenerBadDataTest | ||
| { | ||
| /** Port for the first lateral node */ | ||
| private static final int LISTENER_PORT_1 = 11261; | ||
|
|
||
| /** Port for the second lateral node */ | ||
| private static final int LISTENER_PORT_2 = 11262; | ||
|
|
||
| /** Cache region name used in the test */ | ||
| private static final String CACHE_REGION = "testBadDataRegion"; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() throws Exception | ||
| { | ||
| // Configure a 2-node lateral TCP cluster programmatically | ||
| final java.util.Properties props = new java.util.Properties(); | ||
|
|
||
| // Default cache region | ||
| props.put("jcs.default", ""); | ||
| props.put("jcs.default.cacheattributes", | ||
| "org.apache.commons.jcs3.engine.CompositeCacheAttributes"); | ||
| props.put("jcs.default.cacheattributes.MaxObjects", "100"); | ||
|
|
||
| // Test region with lateral TCP auxiliary | ||
| props.put("jcs.region." + CACHE_REGION, "LTCP"); | ||
| props.put("jcs.region." + CACHE_REGION + ".cacheattributes", | ||
| "org.apache.commons.jcs3.engine.CompositeCacheAttributes"); | ||
| props.put("jcs.region." + CACHE_REGION + ".cacheattributes.MaxObjects", "100"); | ||
|
|
||
| // Lateral TCP auxiliary - this node listens on LISTENER_PORT_1 | ||
| // and connects to the peer on LISTENER_PORT_2 | ||
| props.put("jcs.auxiliary.LTCP", | ||
| "org.apache.commons.jcs3.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory"); | ||
| props.put("jcs.auxiliary.LTCP.attributes", | ||
| "org.apache.commons.jcs3.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes"); | ||
| props.put("jcs.auxiliary.LTCP.attributes.TcpListenerPort", | ||
| String.valueOf(LISTENER_PORT_1)); | ||
| props.put("jcs.auxiliary.LTCP.attributes.TcpServers", | ||
| "localhost:" + LISTENER_PORT_2); | ||
| props.put("jcs.auxiliary.LTCP.attributes.IssueRemoveOnPut", "false"); | ||
| props.put("jcs.auxiliary.LTCP.attributes.AllowGet", "true"); | ||
| props.put("jcs.auxiliary.LTCP.attributes.UdpDiscoveryEnabled", "false"); | ||
|
|
||
| JCS.setConfigProperties(props); | ||
| JCS.getInstance(CACHE_REGION); | ||
|
|
||
| // Give the listener a moment to start up | ||
| TimeUnit.MILLISECONDS.sleep(500); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception | ||
| { | ||
| JCS.shutdown(); | ||
| } | ||
|
|
||
| /** | ||
| * Verifies that the listener continues to accept new connections after | ||
| * receiving bad data. This is a simple check — just confirm that | ||
| * connecting to the port doesn't throw an exception. Before the fix this fails. | ||
| */ | ||
| @Test | ||
| public void testListenerAcceptsConnectionsAfterBadData() throws Exception | ||
| { | ||
| // Send bad data first | ||
| try (Socket badSocket = new Socket("localhost", LISTENER_PORT_1)) | ||
| { | ||
| final ObjectOutputStream oos = | ||
| new ObjectOutputStream(badSocket.getOutputStream()); | ||
| oos.writeObject(0); // Not a LateralElementDescriptor | ||
| oos.flush(); | ||
| } | ||
|
|
||
| TimeUnit.MILLISECONDS.sleep(500); | ||
|
|
||
| // Verify we can still connect — the ServerSocket is still accepting | ||
| boolean connected; | ||
| try (Socket testSocket = new Socket("localhost", LISTENER_PORT_1)) | ||
| { | ||
| connected = testSocket.isConnected(); | ||
| } | ||
|
|
||
| assertTrue( | ||
| "Should still be able to connect to the listener port after bad data was sent.", | ||
| connected); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not edit this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified it, as some pipelines were failing and was getting notifications quite often on this