Run client connection handler inside new thread, fixes #798 (#801)

* Run client connection handler inside new thread, fixes #798
* Execute CI build on ubuntu-22.04
 * ubuntu-18.04 image is now deprecated and there are brownout periods
   being introduced where the builds are failing
 * see https://github.com/actions/runner-images/issues/6002 for more
   details
This commit is contained in:
Petr Široký
2023-03-07 14:16:04 +01:00
committed by GitHub
parent 0b55c8f3e6
commit 1f99fb8cb7
2 changed files with 12 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ ubuntu-18.04, macOS-10.15, windows-2019 ] os: [ ubuntu-22.04, macOS-10.15, windows-2019 ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:

View File

@@ -239,7 +239,16 @@ public class Server implements AutoCloseable, Runnable {
try { try {
while (true) { while (true) {
try (SocketChannel socket = this.socket.accept()) { try (SocketChannel socket = this.socket.accept()) {
client(socket); try {
// execute the client connection handling inside a new thread to guard against possible
// ThreadLocal memory leaks
// see https://github.com/apache/maven-mvnd/issues/798 for more details
Thread handler = new Thread(() -> client(socket));
handler.start();
handler.join();
} catch (Throwable t) {
LOGGER.error("Error handling a client connection", t);
}
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
@@ -270,7 +279,7 @@ public class Server implements AutoCloseable, Runnable {
updateState(DaemonState.Idle); updateState(DaemonState.Idle);
return; return;
} }
LOGGER.info("Request received: " + message); LOGGER.info("Request received: {}", message);
if (message instanceof BuildRequest) { if (message instanceof BuildRequest) {
handle(connection, (BuildRequest) message); handle(connection, (BuildRequest) message);
} }