「ランダム」な502エラー

GCE サーバー上で Discourse をインストールして運用しています。ユーザーから、システムがランダムに 502 エラーを返すという問題が報告されています。Latest、New、Unread、Top、Categories のリンクを順にクリックすると、この状況を再現できます。いずれかのリンクで 502 エラーが返ってくるのです。

プロキシサーバーのログを確認したところ、失敗した URL に対して以下のようなエントリが記録されていました。
“upstream prematurely closed connection while reading response header from upstream”(アップストリームからのレスポンスヘッダーの読み取り中に、アップストリームが接続を早期に閉じました)。これらエラーは、一見ランダムな URL に対して非常に多数発生しています。

これまで見た投稿に基づき、問題解決のために以下の手順を踏みました。

  • OS のアップグレード
  • Docker のアップグレード
  • Discourse のアップグレード
  • サーバーの再起動

当初のインストールは Docker Cloud Setup ガイドに従って行いました。その後、バックアップとイメージを S3 を使用するように切り替えるガイドに従いました。

サーバーの仕様は以下の通りです。
Ubuntu 14.04.6 LTS (GNU/Linux 4.4.0-148-generic x86_64)

discourse-doctor の出力結果:

     DOCKER VERSION: Docker version 18.06.3-ce, build d7080c1

==================== MEMORY INFORMATION ====================
RAM (MB): 4820

             total       used       free     shared    buffers     cached
Mem:          4707       2206       2501        140        101        948
-/+ buffers/cache:       1156       3550
Swap:         2047          0       2047

==================== DISK SPACE CHECK ====================
---------- OS Disk Space ----------
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   33G   15G  70% /
/dev/sda1        50G   33G   15G  70% /var/lib/docker

==================== DISK INFORMATION ====================

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *       16065   104856254    52420095   83  Linux
Partition 1 does not start on physical sector boundary.

==================== END DISK INFORMATION ====================

top コマンドを実行して CPU とメモリの数値を観察しましたが、懸念すべき点は見当たりませんでした。ログも確認しましたが、問題の原因を示すものは見つかりませんでした。

問題のトラブルシューティングに役立つ他の詳細情報はありますか?また、この原因を特定するために取るべき手順は何でしょうか?

よろしくお願いいたします。

Stephen

It could be that Postgres needs a bit more memory. You’ve got plenty, so you might bump db_shared_buffers to 1024MB. You might also bump db_work_mem to 80MB.

Thank you for the suggestion. I made both of those changes in the yml file. Restarting the app didn’t seem to make a difference, so I ended up rebooting the server. Unfortunately I can still replicate the problem.

You need to rebuild or

cd /var/discourse
./launcher destroy app
./launcher start app

for the changes to take effect.

And, this might not be a silver bullet, but I have seen it help.

So far so good, we’ll monitor and see how this helps. Thank you!