gcpug / nouhau

Google Cloud Platformのノウハウを共有するRepository
https://gcpug.jp
MIT License
655 stars 23 forks source link

appengine/go で go1.8になって死ぬ理由一覧 #5

Closed vvakame closed 4 years ago

vvakame commented 6 years ago

みんな好きに書いてね!

vvakame commented 6 years ago

結論:netcontextとcontext周りで死ぬ

vvakame commented 6 years ago

あとライブラリのビルドタグで死んだパターンも聞いた

mstssk commented 6 years ago

WARNING WriteHeader called multiple times on request. を放置しているといつの間にか挙動が変わっていた。

存在しないページではAngularにNotFound画面を出させつつ、検索エンジンのクローラのためにHTTPステータスコードを404を返そうとして↓みたいなコード書いていたら、 api_version: go1 のままだとレスポンスボディにindex.htmlが入らなくなった。

ucon.HandleFunc("GET", "/", func(w http.ResponseWriter, r *http.Request, c context.Context) {

    /** 中略 */

    if isAllowedPath(r.URL.Path) == false {
        w.WriteHeader(404) // SEOのため許容していないパスへのリクエストは404にする
    }
    http.ServeFile(w, r, "dist/index.html") // Angularのindex.html返す。※この中でもw.WriteHeader()は呼ばれている
})

api_version: go1.6 でデプロイしなおしたら従来の動作(レスポンスのステータスコードが404になりつつindex.htmlも落ちてくる)に戻った。

vvakame commented 6 years ago

tenntennさんの記事も見るとよい