Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

閉じられたチャネルにエラーが流れ込む可能性がある #16

Open
KawaiKenta opened this issue Oct 1, 2024 · 0 comments

Comments

@KawaiKenta
Copy link
Contributor

バグの説明

現在、認証のためのWebサーバーを一時的に立てており、リクエストの結果やサーバーのエラーをチャネルを使ってメインスレッドに渡している。
チャネルにリクエスト結果が渡るとその時点でチャネルは閉じられる。
この振る舞いによって、閉じられたチャネルにエラーが流れ込む可能性がある。

具体的には

if err := server.ListenAndServe(); err != nil {
	if !errors.Is(err, http.ErrServerClosed) {
		// サーバー停止以外のエラーをエラーとする
		resultCh <- Result{"", err}
	}
}

この部分について、認証リクエストが処理されてから、サーバーが停止するときにエラーが発生すると、閉じられたチャネルにエラーが流れ込んでしまいパニックになる可能性があるのではないかと疑っている。

想定される原因・修正方法

並行処理やチャネルを使って通信していることが原因なので、非同期をやめ同期的に処理するようにしたら良さそう

補足

  • これが原因でエラーに遭遇したことはありません
  • サーバー停止以外のエラーがあり得なければ、問題なさそうに思います
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant