AR ホームベーカリー

オイラのアウトプット用ホームベーカリー!

possible SYN flooding on port XXXX. Sending cookies.

慌てないのが一番です。 ぼくは徹夜でリリースなのと、前日夜に風邪を発症して全身が痛いでしゅ……。

Serverから応答がない!

httpの監視をしていたサービスが急遽failedを送信してきました。 そのサーバはいつも夜間のバックアップやバッチ実行時、よくスワップアウトして度々警告がくる環境です。 たぶんそんな環境もあるでしょう。

ここで慌てずdmesgです。

[root@localhost ~]# dmesg
...
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.
possible SYN flooding on port 3306. Sending cookies.

OOM Killerかと思いましたが違うようですね。3306といえばMySQLです。グローバルに開放はしていませんがどうしたのでしょう。プロセスの状態を確認してみます。

[root@localhost ~]# /etc/init.d/mysqld status
mysqld (pid 11451) is running...

動作していますね? ではSYN floodingとはなんでしょう。以下の記述が参考になります。

小岩以上アキバ未満~記憶のディザスター~: CentOS6などでdmesgにpossible SYN flooding on port(SYN flooding警告)が出た場合の対策方法を考えてみるテスト

サーバーで受け付けられない(受け付けてない)SYNが大量に来た場合にサーバーがどうしたかを教えてくれている模様。

どこからかアタックを食らったのかもしれませんね。 MySQLのプロセスを再起動してみましょう。

[root@localhost ~]# /etc/init.d/mysqld stop
[root@localhost ~]# /etc/init.d/mysqld start

restartしないのはサーバのSWAPが9割食われてて一度失敗したからです。 これで再起動できた後しばらくおけば、正常にアクセスできるようになるはずです。

rvm gemset copyするときに注意すること

gemset copyした

rubyバージョンアップにともなって、した。

rvm gemset copy 1.9.3-p551@rails 2.0.0-p648@rails

そもそもメンテナンス切れてるバージョンやんけ!みたいなツッコミは勘弁してくだち……。 んでcopyしたら、gemsetの中にbundler入ってなくてデプロイしたアプリ動かなくて死ぬかと思った。

cannot load such file -- bundler/setup (LoadError)

productionモードだと、nginxのアクセスログに500出すだけで、production.logまで到達しなくて何事かと思った。

        location / {
            passenger_enabled on;
            rails_env development;
        }

developmentで動かすことでエラーが見えたので、gem listしたらbundlerがなくてうわぁぁぁ。 gem install bundlerしてNginx再起動したら無事動作して、めでたしめでたし。

gitでバイナリがコンフリクトして爆発した

うおおおmasterに取り込むときに発生するのはやめろー!心臓に悪い!

爆発した

コンテンツの修正で、feature/modify_images_20160805などというブランチで作業していた所、pushしてgitlabからmerge rewuest出したら「コンフリクトしてだめなんでコマンドラインで解決して?」と言われるなどしたので。

[example@localhost example-temp]$ git push origin master
To git@git.example.co.jp:example/example.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@git.example.co.jp:example/example.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.
[example@localhost example-temp]$ git pull
warning: Cannot merge binary files: img/img_main.png (HEAD vs. 114514.......................)

Auto-merging img/img_main.png
CONFLICT (content): Merge conflict in img/img_main.png
Automatic merge failed; fix conflicts and then commit the result.

うおおおおおお?!

どうする

gitlabの提示した解決方法が何も役に立たなくてあーん?みたいになったので、以下のようにcheckout --theirsして解決しました。

[example@localhost example-temp]$ git checkout --theirs img/img_main.png
[example@localhost example-temp]$ git add img/img_main.png
[example@localhost example-temp]$ git commit -m "conflictの解消"
[example@localhost example-temp]$ git push origin master

--theirsだとmasterに元々存在するファイルになるようです。 とりあえずこれで解消できたのでよかった……。 ダメな場合は、reset --hardとかして過去ま戻るしかないかも。

mapyo.hatenablog.com

d.hatena.ne.jp

Sent fileで0バイトのファイルが送られてくる時

わりと忘れがち。

/config/enviroments/production.rb

Apacheの場合は「X-Sendfile」、Nginxの場合は「X-Accel-Redirect」を使う。

  # Specifies the header that your server uses for sending files
  #config.action_dispatch.x_sendfile_header = "X-Sendfile"

  # For nginx:
  #config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

Capistrano3で更新が反映されない時

なんか更新が反映されないな?

と思った時に確認するファイル。

  • config/deploy.rb
  • config/deploy/STAGE
  • /path/to/app/repo/FETCH_HEAD
  • /path/to/app/repo/HEAD
  • /path/to/app/repo/config

特にリポジトリ切り替えたり、検証で複数のリポジトリ行ったり来たりする時、FETCH_HEAD/HEAD/configあたり見るとずっと古いリポジトリの情報書いてあって「あびゃあ」って顔になる。 なんかCapistranoの使い方間違ってる気がするけど、前のエントリでも書いたとおり、repoディレクトリをとりあえず削除することで回避できるから何も考えずにそうしてるマン。

stackoverflowに書いてあった

stackoverflow.com

よく読んでないけどrepo消せって書いてあるし、さすがやなって。

その後

既存の本番環境にURL変更してデプロイするときに躓いた。

astj.hatenablog.com

以下のようにして、set-urlすると解決できるので、むやみにrepoディレクトリを消すのはやめようという知見。

cd /path/to/capistrano/repo
git remote -v

変更前のリポジトリが出てくる

git remote set-url origin "新しいgitリポジトリ"
git remote -v

"新しいgitリポジトリ"に変わってることを確認する

rake-cache 1.6.0はもういない!

budnle installでこけた

古いプロジェクトメンテしようとしたらこけるよー。

Could not find rack-cache-1.6.0 in any of the sources

なくなった

yanked!!

All versions of rack-cache | RubyGems.org | your community gem host

yankedじゃないが

github.com

依存関係のあるgemのバージョンは1.6.0→1.6.1で変わらないようなので、そのままbundle upadte rake-cacheすれば大体の人は解決するでしょう!

どうしても1.6.0が無いとダメな場合

多分Gemfileに以下のように書けばgithubから持ってこれるので、なんとかなると思います。

gem 'rack-cache', :git => 'git@github.com:rtomayko/rack-cache.git', :tag => 'v1.6.0'

当然githubと通信しないといけないので、アカウント取って~/.ssh/configあたりに設定書いといてください。なんかhttpsを指定も出来るみたいだけど、そっちは試してないので……。