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

* Run client connection handler inside new thread, fixes #798
* Execute CI build on ubuntu-22.04
This commit is contained in:
Petr Široký
2023-03-07 14:15:37 +01:00
committed by GitHub
parent 30d464b70f
commit 8af598ee23
2 changed files with 12 additions and 3 deletions

View File

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

View File

@@ -233,7 +233,16 @@ public class Server implements AutoCloseable, Runnable {
try {
while (true) {
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) {
@@ -264,7 +273,7 @@ public class Server implements AutoCloseable, Runnable {
updateState(DaemonState.Idle);
return;
}
LOGGER.info("Request received: " + message);
LOGGER.info("Request received: {}", message);
if (message instanceof BuildRequest) {
handle(connection, (BuildRequest) message);
}