|
|
@@ -1515,10 +1515,37 @@ struct HostContext::Impl {
|
|
|
options.at("responseType").is_string() &&
|
|
|
options.at("responseType").get<std::string>() == "base64";
|
|
|
|
|
|
+ const int64_t beforeMs = elapsedMs();
|
|
|
auto result = cli.send(req);
|
|
|
- if (!result)
|
|
|
- throw ApiError(ErrCode::Unavailable, "fetch_failed",
|
|
|
- "request to '" + parts->host + "' failed: " + httplib::to_string(result.error()));
|
|
|
+ if (!result) {
|
|
|
+ const int64_t tookMs = elapsedMs() - beforeMs;
|
|
|
+ // The timeouts handed to the client are the run's REMAINING budget,
|
|
|
+ // so a provider slower than that budget fails as a read error -
|
|
|
+ // which httplib words as "Failed to read connection" and which
|
|
|
+ // reads like a network fault. It is not: it is our own deadline.
|
|
|
+ // Saying how long the call was allowed, and how long it took,
|
|
|
+ // makes the two distinguishable without guessing. A consumer
|
|
|
+ // diagnosed exactly this as a stale keep-alive pool, which
|
|
|
+ // ctx.fetch does not even have - every call builds its own client.
|
|
|
+ const bool likelyTimeout = tookMs >= (budget - 1000);
|
|
|
+ const std::string detail =
|
|
|
+ "request to '" + parts->host + "' failed after " + std::to_string(tookMs) +
|
|
|
+ "ms of the " + std::to_string(budget) + "ms this run could still allow it: " +
|
|
|
+ httplib::to_string(result.error());
|
|
|
+ // An operator trace, which this path had none of: a failing
|
|
|
+ // provider was visible ONLY to the tenant, inside their function,
|
|
|
+ // while the journal said nothing. Same hole as the embedding path.
|
|
|
+ spdlog::warn("ctx.fetch {} {} failed after {}ms (budget {}ms, project {}, fn {}) - {}{}",
|
|
|
+ req.method, parts->host, tookMs, budget, config.project,
|
|
|
+ config.functionId, httplib::to_string(result.error()),
|
|
|
+ likelyTimeout ? " [the budget, not the network]" : "");
|
|
|
+ if (likelyTimeout)
|
|
|
+ throw ApiError(ErrCode::GatewayTimeout, "fetch_timeout",
|
|
|
+ detail + " - this is the run's time budget, not the network; "
|
|
|
+ "raise the function's timeoutMs, or move the work to a "
|
|
|
+ "job trigger, whose ceiling is far higher");
|
|
|
+ throw ApiError(ErrCode::Unavailable, "fetch_failed", detail);
|
|
|
+ }
|
|
|
|
|
|
nlohmann::json headers = nlohmann::json::object();
|
|
|
for (const auto& [name, value] : result->headers) headers[name] = value;
|