Skip to content

Commit

Permalink
[JENKINS-49196] Shutdown in a new thread to avoid PrematureEOF
Browse files Browse the repository at this point in the history
Add a new thread to exit Jenkins for the shutdown cli command to avoid
the Premature EOF IOException
  • Loading branch information
MRamonLeon committed Oct 22, 2018
1 parent 34b3a43 commit 8cbfa5e
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -4266,18 +4266,29 @@ protected RestartCause() {
@RequirePOST
public void doExit( StaplerRequest req, StaplerResponse rsp ) throws IOException {
checkPermission(ADMINISTER);
LOGGER.severe(String.format("Shutting down VM as requested by %s from %s",
getAuthentication().getName(), req!=null?req.getRemoteAddr():"???"));
if (rsp!=null) {
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.setContentType("text/plain");
try (PrintWriter w = rsp.getWriter()) {
w.println("Shutting down");
}
}
new Thread("exit thread") {
@Override
public void run() {
try {
ACL.impersonate(ACL.SYSTEM);
LOGGER.severe(String.format("Shutting down VM as requested by %s from %s",
getAuthentication().getName(), req!=null?req.getRemoteAddr():"???"));
if (rsp!=null) {
rsp.setStatus(HttpServletResponse.SC_OK);
rsp.setContentType("text/plain");
try (PrintWriter w = rsp.getWriter()) {
w.println("Shutting down");
}
}

cleanUp();
System.exit(0);

cleanUp();
System.exit(0);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to shut down Jenkins", e);
}
}
}.start();
}


Expand Down

0 comments on commit 8cbfa5e

Please sign in to comment.