Logs failing to flush in `Logdna::Client` due to concurrency issue in rails
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
調査の方向性
Logdna::Client#schedule_flush から始め、Rails のブート中に @scheduled_flush と @work_thread_pool が Concurrent のスケジュールタスクをどのように使用するかを調査します。説明されている Rails 6.1.7.5、Ruby 3.2.2 のセットアップで、config/application.rb からのログ呼び出しも含めて再現します。ブート後も、設定ログが発生する場合にログのフラッシュが継続すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Found that any uses of Logdna::Client within the boot sequence of rails results in subsequent logs never flushing.
For background, using logdna 1.5.0 w/ rails 6.1.7.5 on ruby 3.2.2. Configuring Logdna::Ruby following the instructions in TAMING RUBY ON RAILS LOGGING WITH LOGRAGE AND MEZMO in config/application.rb. As long as Rails.logger isn't used within the subsequent application setup steps, then logging works as expected. But if any other subsequent step of the application setup process attempts to log, then all subsequent logs fail to be emitted.
Tracked this down to Logdna::Client#schedule_flush. By adding logging, I found that the associated Concurrent::ScheduledTask in @scheduled_flush remains in the pending state indefinitely. Further logging shows that the ScheduledTask is associated with a Concurrent::CachedThreadPool that contains a single thread and that thread has is marked as dead.
Guessing that as part of the rails boot up process, the default executor is terminated and therefore the @scheduled_flush never completes. Not that using the @work_thread_pool thread pool doesn't fix the issue; the same behavior is observed. By not logging anything during rails configurations/boot, a ScheduledTask isn't created while the application is still booting, and therefore this issue doesn't occur.
I think this issue could be addressed by tracking the time at which @scheduled_flush is created and then in subsequent invocations of schedule_flush checking if it has been pending far longer than expected. If it is sufficiently stale, then the outstanding ScheduledTask would be cancelled and a new one created. There may be more robust/elegant ways to address this because I'm not particularly familiar with ruby/rails thread management.
- 主要言語
- Ruby
- スター
- 19
- フォーク
- 18
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
logdna/ruby のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 30/100
似ている issue
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
benbalter/jekyll-include-cache#55 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
security
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
grafana/pyroscope#5729 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`rake gemcutter:index:update` fails on Ruby 4.0対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rubygems/rubygems.org#6895 ·
メンテナーはふだん 1 日以内に返信