{"record":{"id":"9163fb64aca2f5ba","repo":"fish2018/pansou","slug":"s-w-9163fb","errorCode":null,"errorMessage":"[%s] 搜索会话请求失败: %w","messagePattern":"\\[(.+?)\\] 搜索会话请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/jupansou/jupansou.go","lineNumber":183,"sourceCode":"\n\tresults := p.exchangeItems(client, filteredItems)\n\treturn plugin.FilterResultsByKeyword(results, keyword), nil\n}\n\nfunc (p *JuPansouPlugin) ensureSearchSession(client *http.Client) error {\n\tctx, cancel := context.WithTimeout(context.Background(), jupansouTimeout)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, jupansouBaseURL+\"/api/search/session\", nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"[%s] 创建搜索会话请求失败: %w\", p.Name(), err)\n\t}\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\treq.Header.Set(\"Referer\", jupansouBaseURL+\"/\")\n\treq.Header.Set(\"X-Requested-With\", \"XMLHttpRequest\")\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"[%s] 搜索会话请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"[%s] 搜索会话返回状态码: %d\", p.Name(), resp.StatusCode)\n\t}\n\treturn nil\n}\n\nfunc (p *JuPansouPlugin) exchangeItems(client *http.Client, items []juPansouStreamItem) []model.SearchResult {\n\tresults := make([]model.SearchResult, 0, len(items))\n\tvar wg sync.WaitGroup\n\tvar mu sync.Mutex\n\tsem := make(chan struct{}, 8)\n\tseen := make(map[string]struct{})\n\tfor _, item := range items {\n\t\titem := item\n\t\tif item.URL == \"\" {\n\t\t\tcontinue","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/jupansou/jupansou.go#L165-L201","documentation":"ensureSearchSession wraps errors from client.Do when the session-establishment request to /api/search/session fails at transport level. Without a successful session the subsequent search may fail, so this is a prerequisite-step failure. The cause is preserved via %w.","triggerScenarios":"client.Do for the session request returns an error: DNS failure, connection refused, TLS error, or the jupansouTimeout context expiring before a response arrives.","commonSituations":"Upstream site down or domain changed; the session endpoint removed/blocked; network egress blocked in the deployment environment; jupansouTimeout too short for a slow upstream.","solutions":["Unwrap the error to identify timeout vs connection failure.","curl jupansouBaseURL/api/search/session from the host to confirm reachability.","Increase jupansouTimeout if the endpoint is slow.","Update the plugin if the upstream removed or moved the session endpoint.","Check proxy/firewall rules for the deployment host."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"conn, err := net.DialTimeout(\"tcp\", host, 3*time.Second)\nif err != nil { return fmt.Errorf(\"upstream unreachable before search: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"if err := p.ensureSearchSession(client); err != nil {\n    var nerr net.Error\n    if errors.As(err, &nerr) && nerr.Timeout() {\n        log.Println(\"session establishment timed out; retrying with longer timeout\")\n    } else {\n        log.Printf(\"session request failed: %v\", err)\n    }\n    // degrade: proceed without session or skip this source\n}","preventionTips":["Probe the session endpoint during plugin startup health checks.","Set jupansouTimeout above typical upstream latency (measure it first).","Handle session failure as degradation, not a hard failure, if searches can proceed."],"tags":["network","http","session","timeout"],"backgroundTag":"http-request-failed","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}