googleapis/mcp-toolbox · error
failed to execute request: %w
Error message
failed to execute request: %w
What it means
FetchQueryStats executes the HTTP POST via s.httpClient.Do. Any transport-level failure (DNS, connection refused, TLS, timeout, context cancellation) is wrapped in this error. It means the API call never completed with an HTTP response.
Source
Thrown at internal/sources/databaseinsights/databaseinsights.go:379
// FetchQueryStats executes the FetchQueryStats REST API method.
func (s *Source) FetchQueryStats(ctx context.Context, req *FetchQueryStatsRequest) (*FetchQueryStatsResponse, error) {
url := fmt.Sprintf("%s/v1beta/%s/queryStats:fetch", s.getEndpointForParent(req.Parent), req.Parent)
bodyBytes, err := json.Marshal(req)
if err != nil {
return nil, fmt.Errorf("failed to marshal request: %w", err)
}
httpReq, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(bodyBytes))
if err != nil {
return nil, fmt.Errorf("failed to create http request: %w", err)
}
httpReq.Header.Set("Content-Type", "application/json")
resp, err := s.httpClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("failed to execute request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(resp.Body)
return nil, fmt.Errorf("request failed with status %s: %s", resp.Status, string(respBody))
}
var fetchResp FetchQueryStatsResponse
if err := json.NewDecoder(resp.Body).Decode(&fetchResp); err != nil {
return nil, fmt.Errorf("failed to decode response: %w", err)
}
return &fetchResp, nil
}
// FetchWaitEventStats executes the FetchWaitEventStats REST API method.
func (s *Source) FetchWaitEventStats(ctx context.Context, req *FetchWaitEventStatsRequest) (*FetchWaitEventStatsResponse, error) {View on GitHub (pinned to 8cc6e09de2)
Solutions
- Check the wrapped error: verify DNS and TCP connectivity to the endpoint host (e.g. curl the URL)
- Confirm egress/firewall/proxy rules allow HTTPS to googleapis.com or the custom endpoint
- If using a custom endpoint, verify it is reachable and serving the v1beta API
- Increase HTTP client timeout or review context deadlines
- Ensure TLS trust store includes the CA for any proxy/interception
Example fix
// before ctx := context.Background() // no deadline; hangs until client timeout resp, err := s.FetchQueryStats(ctx, req) // after ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() resp, err := s.FetchQueryStats(ctx, req)
Defensive patterns
Strategy: retry
Validate before calling
conn, err := net.DialTimeout("tcp", "databaseinsights.googleapis.com:443", 5*time.Second)
if err != nil { return fmt.Errorf("no connectivity to API endpoint: %w", err) }
conn.Close() Try / catch
resp, err := src.FetchQueryStats(ctx, req)
if err != nil && strings.Contains(err.Error(), "failed to execute request") {
if errors.Is(ctx.Err(), context.DeadlineExceeded) { /* increase timeout */ }
// retry with exponential backoff for transient network errors
return retryWithBackoff(ctx, func() error { _, err := src.FetchQueryStats(ctx, req); return err })
} Prevention
- Set realistic context timeouts for large stat fetches
- Verify egress/firewall access to googleapis.com in each environment
- Check proxy/TLS trust configuration in corporate networks
- Monitor connectivity before scheduling bulk fetches
When it happens
Trigger: httpClient.Do returns a non-nil error: network unreachable, DNS failure, TLS handshake failure, request timeout, or ctx canceled before completion.
Common situations: No outbound network access or blocked egress to googleapis.com; wrong custom endpoint host; corporate proxy/TLS interception without trusted roots; client timeout too short for large fetches; caller canceled the context.
Related errors
- failed to fetch OIDC config: %w
- failed to execute pipeline request: %w
- failed to read introspection response: %w
- failed to read response body: %w
- error performing request: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/04566abb43db2670.
Report an issue: GitHub.