Skip to content

Commit bef9e60

Browse files
authored
Hotfix for non-shutdown of http server (#13485)
1 parent 891a6dc commit bef9e60

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

jabsrv/src/main/java/org/jabref/http/manager/HttpServerManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public synchronized void start(ObservableList<BibDatabaseContext> contextsToServ
2525
if (!isStarted()) {
2626
httpServerThread = new HttpServerThread(contextsToServe, uri);
2727
httpServerThread.start();
28+
if (httpServerThread.started()) {
29+
LOGGER.debug("HTTP server manager started successfully.");
30+
} else {
31+
LOGGER.error("Failed to start HTTP server manager.");
32+
httpServerThread = null;
33+
}
2834
}
2935
}
3036

jabsrv/src/main/java/org/jabref/http/manager/HttpServerThread.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jabref.http.server.Server;
88
import org.jabref.model.database.BibDatabaseContext;
99

10+
import jakarta.ws.rs.ProcessingException;
1011
import org.glassfish.grizzly.http.server.HttpServer;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
@@ -33,13 +34,25 @@ public HttpServerThread(ObservableList<BibDatabaseContext> contextsToServe, URI
3334

3435
@Override
3536
public void run() {
36-
httpServer = this.server.run(contextsToServe, uri);
37+
try {
38+
httpServer = this.server.run(contextsToServe, uri);
39+
} catch (ProcessingException e) {
40+
LOGGER.error("Failed to start HTTP server thread: {}", e);
41+
}
3742
}
3843

3944
@Override
4045
public void interrupt() {
4146
LOGGER.debug("Interrupting {}", this.getName());
42-
this.httpServer.shutdownNow();
47+
if (this.httpServer == null) {
48+
LOGGER.warn("HttpServer is null, cannot shutdown.");
49+
} else {
50+
this.httpServer.shutdownNow();
51+
}
4352
super.interrupt();
4453
}
54+
55+
public boolean started() {
56+
return httpServer != null && httpServer.isStarted();
57+
}
4558
}

0 commit comments

Comments
 (0)