ステータスとロードタイムのhttp/sエンドポイントをチェックするコードがあります。次に、各トップレベルページimがレベル-1のhrefをチェックするために、ページが参照しているすべてが200でロードされていることを確認します。net/http vs curl - なぜカールがどこにないのですか?
(私は50本の、トップレベルのページをチェックし、各トップレベルのページは、8つのリンクの平均であり)
私はいくつかのゴルーチン(25)とwaitgroupを経由して、トップレベルのページをご確認ください。レベル1のページでは、別のgouroutines + waitgroupを試してから、まっすぐなforloopを試してみました。
これらのレベル1ページでは、「CLient.Timeoutがヘッダーを待つ間に超過しました」というエラーが多く発生しています。そのようなURLをつかんですぐにカールして再試行すると、カールで完全にロードされます。
ヘッダーのタイムアウトのページは、js、png、gif、htmlが混在しています。私は手動でそれをカールするときに完璧に動作する通常のものは、何とかしてから大きな時間を失敗します。
以下は、ページの内容を取得するために呼び出す関数です。
func (t Target) getContents(timeout int64) (string, string, string) {
var contents []byte
statusCode := "0"
errorLabel := "no_error"
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
// Dial: (&net.Dialer{
// Timeout: 15 * time.Second,
// KeepAlive: 15 * time.Second,
// }).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
client := &http.Client{Transport: tr, Timeout: time.Duration(timeout) * time.Second}
url := t.getPageURL()
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Error("Error while creating the request| ", err)
errorLabel = "cant_create_request"
} else {
//req.Header.Add("cache-control", "no-cache")
if t.Agent != "" {
req.Header.Set("User-Agent", t.Agent)
}
if t.SourceIP != "" {
req.Header.Set("X-Forwarded-For", t.SourceIP)
}
if t.Host != "" {
req.Header.Set("Host", t.Host)
req.Host = t.Host
}
response, err := client.Do(req)
if err != nil {
log.Error("Error while doing the request| ", err.Error())
errorLabel = "cant_do_request"
} else {
defer response.Body.Close()
statusCode = strconv.Itoa(response.StatusCode)
contents, err = ioutil.ReadAll(response.Body)
if err != nil {
log.Error("Error while reading the response| ", err)
errorLabel = "cant_read_response"
}
}
}
return string(contents), statusCode, errorLabel
}
ここでは十分ではありませんが、壊れたipv6ネットワークはこのように動作します。とにかくあなたのダイヤラーで 'DualStack'を有効にする必要があります。これはその問題を回避します。 – JimB
ああ、接続をリークする「http.Transport」は決して捨てないでください。 – JimB
モデレータが私のコメントを削除したようです - はい、私は誤った構成のオフィスネットワークに犠牲になりました。 「適切な」場所に配置すると、エクスポータはもはやタイムアウトしません。 –