diff --git a/commafeed-server/src/main/java/com/commafeed/backend/HttpGetter.java b/commafeed-server/src/main/java/com/commafeed/backend/HttpGetter.java index 6dd28f06..4343135f 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/HttpGetter.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/HttpGetter.java @@ -237,6 +237,7 @@ public class HttpGetter { contentType, urlAfterRedirect); } catch (InterruptedException e) { + future.cancel(true); Thread.currentThread().interrupt(); throw new RuntimeException("interrupted while fetching " + request.getUrl(), e); } catch (ExecutionException e) { diff --git a/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java b/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java index 93246251..91b81d19 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java @@ -17,13 +17,13 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; -import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder; import org.apache.hc.client5.http.async.methods.SimpleRequestProducer; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.Message; import org.apache.hc.core5.http.NameValuePair; import org.apache.hc.core5.http.message.BasicNameValuePair; import org.apache.hc.core5.http.nio.entity.DiscardingEntityConsumer; @@ -36,6 +36,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; @Singleton @Slf4j @@ -198,20 +199,19 @@ public class PushNotificationService { } private void send(String name, SimpleHttpRequest request) throws IOException { + Future> future = + httpClient.execute( + SimpleRequestProducer.create(request), + new BasicResponseConsumer<>(new DiscardingEntityConsumer<>()), + null); try { - HttpResponse response = - httpClient - .execute( - SimpleRequestProducer.create(request), - new BasicResponseConsumer<>(new DiscardingEntityConsumer<>()), - null) - .get() - .getHead(); + HttpResponse response = future.get().getHead(); if (response.getCode() >= 400) { throw new PushNotificationException( name + " notification failed with status " + response.getCode()); } } catch (InterruptedException e) { + future.cancel(true); Thread.currentThread().interrupt(); throw new IOException("interrupted while sending " + name + " notification", e); } catch (ExecutionException e) {