{"record":{"id":"04566abb43db2670","repo":"googleapis/mcp-toolbox","slug":"failed-to-execute-request-w","errorCode":null,"errorMessage":"failed to execute request: %w","messagePattern":"failed to execute request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/databaseinsights/databaseinsights.go","lineNumber":379,"sourceCode":"\n// FetchQueryStats executes the FetchQueryStats REST API method.\nfunc (s *Source) FetchQueryStats(ctx context.Context, req *FetchQueryStatsRequest) (*FetchQueryStatsResponse, error) {\n\turl := fmt.Sprintf(\"%s/v1beta/%s/queryStats:fetch\", s.getEndpointForParent(req.Parent), req.Parent)\n\n\tbodyBytes, err := json.Marshal(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal request: %w\", err)\n\t}\n\n\thttpReq, err := http.NewRequestWithContext(ctx, \"POST\", url, bytes.NewBuffer(bodyBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create http request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tresp, err := s.httpClient.Do(httpReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\trespBody, _ := io.ReadAll(resp.Body)\n\t\treturn nil, fmt.Errorf(\"request failed with status %s: %s\", resp.Status, string(respBody))\n\t}\n\n\tvar fetchResp FetchQueryStatsResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&fetchResp); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode response: %w\", err)\n\t}\n\n\treturn &fetchResp, nil\n}\n\n// FetchWaitEventStats executes the FetchWaitEventStats REST API method.\nfunc (s *Source) FetchWaitEventStats(ctx context.Context, req *FetchWaitEventStatsRequest) (*FetchWaitEventStatsResponse, error) {","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/databaseinsights/databaseinsights.go#L361-L397","documentation":"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.","triggerScenarios":"httpClient.Do returns a non-nil error: network unreachable, DNS failure, TLS handshake failure, request timeout, or ctx canceled before completion.","commonSituations":"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.","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"],"exampleFix":"// before\nctx := context.Background() // no deadline; hangs until client timeout\nresp, err := s.FetchQueryStats(ctx, req)\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\nresp, err := s.FetchQueryStats(ctx, req)","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", \"databaseinsights.googleapis.com:443\", 5*time.Second)\nif err != nil { return fmt.Errorf(\"no connectivity to API endpoint: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"resp, err := src.FetchQueryStats(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"failed to execute request\") {\n  if errors.Is(ctx.Err(), context.DeadlineExceeded) { /* increase timeout */ }\n  // retry with exponential backoff for transient network errors\n  return retryWithBackoff(ctx, func() error { _, err := src.FetchQueryStats(ctx, req); return err })\n}","preventionTips":["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"],"tags":["network","http","timeout"],"backgroundTag":"request-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}