siyuan-note/siyuan · error
request failed:
Error message
request failed:
What it means
HTTPRequest wraps the Go net/http client (ssrfSafeClient) to fetch a URL for agent processing. This error is returned when the client's Do(req) call fails at the transport level, and the underlying error text is appended after the "request failed: " prefix. It means the HTTP round trip never produced a response: DNS failure, connection refused/reset, TLS handshake error, timeout, or an SSRF-guard rejection inside the custom transport.
Solutions
- Read the appended underlying error text to identify the cause (no such host, connection refused, TLS, timeout) and fix accordingly
- Verify the URL is correct, reachable (curl it from the same machine), and uses http/https with a valid port
- If the target is a private/loopback address, move the resource to a publicly reachable endpoint — the SSRF-safe client intentionally blocks internal addresses
- Check DNS resolution and outbound network/firewall/proxy configuration on the host
- For TLS errors, fix the server certificate or install the needed CA; do not attempt to bypass the SSRF guard
Example fix
// before status, ctype, out, err := util.HTTPRequest(ctx, "http://localhost:6806/api/x") // after — use a reachable, public URL status, ctype, out, err := util.HTTPRequest(ctx, "https://example.com/resource")
Defensive patterns
Strategy: retry
Validate before calling
u, err := url.Parse(target)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") { return fmt.Errorf("invalid URL") }
if host, _, e := net.SplitHostPort(u.Host); e == nil && (net.ParseIP(host).IsLoopback() || net.ParseIP(host).IsPrivate()) { return fmt.Errorf("SSRF guard will block private address") } Try / catch
if err != nil && strings.HasPrefix(err.Error(), "request failed:") {
// inspect underlying cause; retry transient errors with backoff
} Prevention
- Validate URLs (scheme + public reachability) before calling
- Retry transient network errors with backoff
- Monitor host DNS/firewall health
- Never expect loopback/LAN URLs to work — the SSRF guard blocks them
When it happens
Trigger: Calling HTTPRequest (via httpRequestHandler) with an unreachable host, a hostname that does not resolve, a closed port, a TLS certificate mismatch, a request context timeout/cancellation, or a URL blocked by the SSRF-safe client (private/loopback addresses, disallowed schemes).
Common situations: Typo in the target URL or hostname; the remote service is down or the port is wrong; the machine running SiYuan has no outbound network/DNS; self-signed or expired certificates; fetching http://127.0.0.1 or LAN addresses that the SSRF guard deliberately blocks; firewalls/proxies intercepting the connection.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- access to private/internal IP is prohibited
- download failed:
- ip address [ ] is prohibited
- read body failed:
- access to private/internal IP is prohibited
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/4a647dc871b0596f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/httprequest.go:335
if method == "" {
method = "GET"
}
var reqBody io.Reader
if body != "" && method != "GET" && method != "HEAD" {
reqBody = strings.NewReader(body)
}
req, err := http.NewRequest(method, rawURL, reqBody)
if err != nil {
return 0, "", "", errors.New("invalid request: " + err.Error())
}
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := ssrfSafeClient.Do(req)
if err != nil {
return 0, "", "", errors.New("request failed: " + err.Error())
}
if resp == nil {
return 0, "", "", errors.New("nil response")
}
defer resp.Body.Close()
statusCode = resp.StatusCode
contentType = resp.Header.Get("Content-Type")
maxReadBytes := int64(maxHTTPRequestBytes)
if !isTextContentType(contentType) {
maxReadBytes = maxHTTPRequestFileBytes
}
// ContentLength 为 -1(chunked)时跳过大小预检,交由 LimitReader 兜底截断。
if resp.ContentLength > maxReadBytes {
return statusCode, contentType, "", errors.New("response too large")
}
View on GitHub (pinned to 9f775e8a12)