Add a connection-timeout as this might resolve cases where the webserver is hanging for a long time

This commit is contained in:
Lukas Rieger (Blue) 2022-11-14 17:24:26 +01:00
parent 1a2d3a6d38
commit 1771768afe
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2

View File

@ -28,10 +28,7 @@
import de.bluecolored.bluemap.core.logger.Logger;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.*;
import java.util.concurrent.*;
@DebugDump
@ -73,7 +70,7 @@ public synchronized void start() {
try {
server = new ServerSocket(port, maxConnections, bindAddress);
server.setSoTimeout(0);
server.setSoTimeout(1000);
} catch (IOException e){
Logger.global.logError("Error while starting the WebServer!", e);
return;
@ -101,7 +98,9 @@ public void run(){
Logger.global.logWarning("Dropped an incoming HttpConnection! (Too many connections?)");
}
} catch (SocketException e){
} catch (SocketTimeoutException ignore) {
// will be thrown regularly if no connection is coming in
} catch (SocketException ignore){
// this mainly occurs if the socket got closed, so we ignore this error
} catch (IOException e){
Logger.global.logError("Error while creating a new HttpConnection!", e);