ginのcontextをgoroutineに渡す際はコピーしなければならない gin/context.goには下記のようなことが書いてあります(zennで見やすいように勝手に改行しました)。 // Copy returns a copy of the current context // that can be safely used outside the request's scope. // (訳: Copyはリクエストスコープの外でも安全に使えるcontextのコピーを作ります) // This has to be used // when the context has to be passed to a goroutine. // (訳: contextをgoroutineに渡す際にはこのメソッドを使う必要があります) 気になるのは、goroutineにcontextを渡す際に
![ginのcontextはpoolを通じて使い回されているので、goroutineに渡すときはCopyしよう](https://cdn-ak-scissors.b.st-hatena.com/image/square/ae615bd8c5007c9ea3574b97222e2b46a51ac7ce/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--dceBROBp--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3Agin%2525E3%252581%2525AEcontext%2525E3%252581%2525AFpool%2525E3%252582%252592%2525E9%252580%25259A%2525E3%252581%252598%2525E3%252581%2525A6%2525E4%2525BD%2525BF%2525E3%252581%252584%2525E5%25259B%25259E%2525E3%252581%252595%2525E3%252582%25258C%2525E3%252581%2525A6%2525E3%252581%252584%2525E3%252582%25258B%2525E3%252581%2525AE%2525E3%252581%2525A7%2525E3%252580%252581goroutine%2525E3%252581%2525AB%2525E6%2525B8%2525A1%2525E3%252581%252599%2525E3%252581%2525A8%2525E3%252581%25258D%2525E3%252581%2525AFCopy%2525E3%252581%252597%2525E3%252582%252588%2525E3%252581%252586%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Acanalun%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3plbm4tdXNlci11cGxvYWQvYXZhdGFyL2UyMGFkNzQ4N2UuanBlZw%3D%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)