alibaba/spring-ai-alibaba · error · WebFetchException

Request was interrupted

Error message

Request was interrupted

What it means

fetchHtml catches InterruptedException from HttpClient.send, restores the interrupt flag, and throws WebFetchException('Request was interrupted'). It means the HTTP request was cancelled by a thread interrupt, not by a network failure.

Source

Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/tools/WebFetchTool.java:346

				}

				@Override
				public URI uri() {
					return byteResponse.uri();
				}

				@Override
				public java.net.http.HttpClient.Version version() {
					return byteResponse.version();
				}
			};
		}
		catch (IOException e) {
			throw new WebFetchException("Network error while fetching URL: " + e.getMessage(), e);
		}
		catch (InterruptedException e) {
			Thread.currentThread().interrupt();
			throw new WebFetchException("Request was interrupted", e);
		}
	}

	private Optional<Charset> extractCharset(HttpResponse<?> response) {
		return response.headers()
			.firstValue("Content-Type")
			.flatMap(contentType -> {
				Matcher matcher = CHARSET_PATTERN.matcher(contentType);
				if (matcher.find()) {
					String charsetName = matcher.group(1);
					try {
						return Optional.of(Charset.forName(charsetName));
					}
					catch (Exception e) {
						logger.warn("Unsupported charset '{}', falling back to UTF-8", charsetName);
						return Optional.empty();
					}
				}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Treat it as cancellation: stop processing and re-check the interrupt flag in your own code.
  2. Locate and adjust the interrupting code (increase timeout, avoid shutdown during in-flight requests).
  3. Catch WebFetchException, check for InterruptedException cause, and return a cancellation status.
  4. Use non-blocking timeouts at a higher level instead of interrupting mid-request where possible.

Example fix

// before
String html = tool.fetch(url);
// after
try {
    String html = tool.fetch(url);
} catch (WebFetchException e) {
    if (e.getCause() instanceof InterruptedException) {
        Thread.currentThread().interrupt();
        throw new TaskCancelledException(url);
    }
    throw e;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    String html = webFetchTool.fetch(url);
} catch (WebFetchException e) {
    if (e.getCause() instanceof InterruptedException) {
        Thread.currentThread().interrupt();
        return null; // cancelled, do not retry
    }
    throw e;
}

Prevention

When it happens

Trigger: Thread interrupt while the blocking HttpClient.send call is in flight — task cancellation, executor shutdownNow, or Future.cancel(true) from a caller imposing a deadline.

Common situations: Agent graph node cancelled by the orchestrator; application shutdown during a fetch; timeouts implemented via interrupting worker threads.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/e1ec260d1a419c29. Report an issue: GitHub.