From a1df7a82ff71d9047d136e691a2f8120aa026efd Mon Sep 17 00:00:00 2001
From: Stefan Triller <t2000@users.noreply.github.com>
Date: Fri, 31 Dec 2021 11:46:36 +0100
Subject: [PATCH] [iCalendar] Fix httpclient getting stuck with broken requests
 (#11866)

* [iCalendar] Fix httpclient getting stuck with broken requests

Fixes #9827

Signed-off-by: Stefan Triller <github@stefantriller.de>
---
 .../icalendar/internal/handler/PullJob.java       | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/PullJob.java b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/PullJob.java
index 045100cc6f4..65db2a29cae 100644
--- a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/PullJob.java
+++ b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/PullJob.java
@@ -102,22 +102,25 @@ class PullJob implements Runnable {
         try {
             response = asyncListener.get(HTTP_TIMEOUT_SECS, TimeUnit.SECONDS);
         } catch (InterruptedException e1) {
-            logger.warn("Download of calendar was interrupted.");
-            logger.debug("InterruptedException message is: {}", e1.getMessage());
+            logger.warn("Download of calendar was interrupted: {}", e1.getMessage());
+            request.abort(e1.getCause() != null ? e1.getCause() : e1);
             return;
         } catch (TimeoutException e1) {
-            logger.warn("Download of calendar timed out (waited too long for headers).");
-            logger.debug("TimeoutException message is: {}", e1.getMessage());
+            logger.warn("Download of calendar timed out (waited too long for headers): {}", e1.getMessage());
+            request.abort(e1.getCause() != null ? e1.getCause() : e1);
             return;
         } catch (ExecutionException e1) {
-            logger.warn("Download of calendar failed.");
-            logger.debug("ExecutionException message is: {}", e1.getCause().getMessage());
+            String msg = e1.getCause() != null ? e1.getCause().getMessage() : "";
+            logger.warn("Download of calendar failed with ExecutionException: {}", msg);
+            request.abort(e1.getCause() != null ? e1.getCause() : e1);
             return;
         }
 
         if (response.getStatus() != HttpStatus.OK_200) {
             logger.warn("Response status for getting \"{}\" was {} instead of 200. Ignoring it.", sourceURI,
                     response.getStatus());
+            request.abort(new IllegalStateException(
+                    "Got response status " + response.getStatus() + " while requesting " + sourceURI));
             return;
         }