bytebase/bytebase · error

failed to send HTTP request

Error message

failed to send HTTP request

What it means

Raised in QueryConn when the basic-auth fallback HTTP client fails to send the parsed REST statement (transport-level error, no usable response). The underlying network error is wrapped and preserved as the cause.

Source

Thrown at backend/plugin/db/elasticsearch/elasticsearch.go:447

					requestPath = "/" + requestPath
				}

				req, err := http.NewRequest(request.Method, requestPath, bytes.NewReader(data))
				if err != nil {
					return errors.Wrapf(err, "failed to create HTTP request")
				}
				req.Header.Set("Content-Type", "application/json")

				// Use OpenSearch client's Stream method which handles AWS signing
				resp, err = d.opensearchClient.Stream(req)
				if err != nil {
					return errors.Wrapf(err, "failed to send HTTP request via OpenSearch client")
				}
			} else {
				// For basic auth, use the basic auth client as before
				resp, err = d.basicAuthClient.Do(request.Method, []byte(request.URL), data)
				if err != nil {
					return errors.Wrapf(err, "failed to send HTTP request")
				}
			}
			defer resp.Body.Close()

			respBytes, err := io.ReadAll(resp.Body)
			if err != nil {
				return errors.Wrap(err, "failed to read response body")
			}

			// Check HTTP status code for errors (4xx, 5xx)
			if resp.StatusCode >= 400 {
				return errors.Errorf("request failed with status code %d: %s", resp.StatusCode, string(respBytes))
			}

			// structure results.
			var result v1pb.QueryResult
			var row v1pb.QueryRow

View on GitHub (pinned to 1870550677)

Solutions

  1. Inspect the wrapped cause for the concrete network failure.
  2. Verify the cluster is up and reachable (Ping or curl the root endpoint) before running the statement.
  3. Check the statement's target path/host and the configured data source address for mismatches.
  4. Address timeout/firewall issues if the statement is large (e.g. _bulk) or the network is constrained.
Defensive patterns

Strategy: retry

Validate before calling

const ok = await fetch(dataSource.address + "/", { signal: AbortSignal.timeout(5000) }).then(r => r.ok).catch(() => false);
if (!ok) throw new Error("basic-auth endpoint unreachable; fix address/network before running statements");

Try / catch

try {
  await driver.queryConn(ctx, conn, statement, qctx);
} catch (e) {
  if (String(e).includes("failed to send HTTP request")) {
    // check e.cause for refused/timeout/TLS and retry transient network errors
  }
  throw e;
}

Prevention

When it happens

Trigger: QueryConn on the non-IAM path: d.basicAuthClient.Do(request.Method, request.URL, data) returns err != nil — connection refused, DNS failure, TLS error, or request timeout while executing the user's REST statement.

Common situations: Cluster unreachable or down at execution time; request URL from the statement forming an unreachable target (bad host baked into the address); TLS mismatch; long-running _search/_bulk timing out due to network limits.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/9551995a7df3ce05. Report an issue: GitHub.