Fix: check if the server is down

This commit is contained in:
Sheepit Renderfarm
2022-06-09 12:26:38 +00:00
parent 3c5b3aba99
commit 5f32bb0346
2 changed files with 36 additions and 1 deletions

View File

@@ -219,7 +219,7 @@ public class Server extends Thread {
this.log.debug("Server::getConfiguration url " + remoteURL.build().toString());
Response response = this.HTTPRequest(remoteURL, formBody);
Response response = this.HTTPRequest(remoteURL, formBody, false);
int r = response.code();
String contentType = response.body().contentType().toString();
@@ -239,6 +239,10 @@ public class Server extends Thread {
this.user_config.setPassword(publickey);
}
}
else if (r == HttpURLConnection.HTTP_NOT_FOUND) {
// most likely the server instance is down but not the frontend proxy (traefik)
return Error.Type.SERVER_DOWN;
}
}
catch (ConnectException e) {
this.log.error("Server::getConfiguration error ConnectException " + e);
@@ -451,6 +455,34 @@ public class Server extends Thread {
}
}
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_, boolean checkIsSuccessful) throws IOException {
String url = httpUrlBuilder.build().toString();
Request.Builder builder = new Request.Builder().addHeader("User-Agent", HTTP_USER_AGENT).url(url);
this.log.debug("Server::HTTPRequest url(" + url + ")");
if (data_ != null) {
builder.post(data_);
}
Request request = builder.build();
Response response = null;
try {
response = httpClient.newCall(request).execute();
if (checkIsSuccessful && !response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
this.lastRequestTime = new Date().getTime();
return response;
}
catch (IOException e) {
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
}
}
public Error.Type HTTPGetFile(String url_, String destination_, Gui gui_, String status_) throws FermeException {
InputStream is = null;
OutputStream output = null;