Skip to content

v2.7.19

Latest

Choose a tag to compare

@matsumotory matsumotory released this 05 Dec 17:06
3680861

Behavior changes: read before upgrading

1. An mruby_set or mruby_set_code argument that interpolates a variable no longer ends the worker or leaves the request without a response (#921)

  • Before: built on nginx 1.31.3, 1.30.4 or 1.30.5, an mruby_set or mruby_set_code directive with extra arguments, one or more of which interpolate a variable (two or more for mruby_set, for example mruby_set $v script.rb "$host" "x";), either ended the worker process (signal 11) or left the request without a response (the connection closed with no reply, curl: (52) Empty reply from server, after about 75 seconds) when the variable was evaluated; which of the two happened depended on the memory layout. The vendored ngx_devel_kit emitted the nginx complex value code without the end code that those nginx versions expect, so the script stack was left short. Built on any other nginx version, including the 1.31.8 and 1.30.6 that ngx_mruby pins, the directive worked, but the evaluated argument kept the length that the length pass had predicted, which can exceed the bytes written; ngx_mruby's set handler does not read that length, so the response was unchanged.
  • Now: on the nginx versions that have the end code (1.30.4 and later 1.30.x, 1.31.3 and later; not freenginx), the vendored ngx_devel_kit appends it, so the argument is evaluated, with a response and without ending the worker, on nginx 1.31.3, 1.30.4 and 1.30.5, and the end code trims the evaluated argument to the bytes written. On nginx before 1.30.4, on 1.31.0 to 1.31.2 and on freenginx, which have no end code, the guard leaves it out and the directive works as before. The response on nginx 1.31.8 and 1.30.6 is unchanged. The documented forms mruby_set $v script.rb; and mruby_set $v script.rb cache;, whose arguments interpolate no variable, were never affected.
  • Why it changed:
    • The defect: mainline nginx 1.31.3 and stable 1.30.4 moved the script stack update of a complex value to a new end code (nginx commit a8289aa69c74). The vendored ngx_devel_kit, which reuses the complex value code in ndk_http_rewrite_value, did not emit it, so the stack was left short and, when the value was evaluated, the worker ended or the request got no response. Mainline nginx 1.31.4 and stable 1.30.6 restored the stack update in the complex value code and turned a missing end code into a result string that keeps the predicted length (nginx commit 4b90ec769235, PR #1601). The nginx 1.30.6 changelog records this fix for third-party modules that use the script codes and notes that the problem appeared in 1.30.4, so the stable releases 1.30.4 and 1.30.5 are affected and 1.30.6 is not.
    • Why the old behavior could not be kept: on nginx 1.31.3, 1.30.4 and 1.30.5 the worker ended or the request got no response, so such a directive could not run there at all; emitting the end code, as nginx's own rewrite module does, is what lets the argument be evaluated and keeps the result string at the bytes written.
    • What the documentation promised: the mruby_set directives of 2.7.18 describe mruby_set $VARNAME /PATH/TO/SCRIPT.rb [cache]; and mruby_set_code $VARNAME 'CODE';, and say nothing about extra arguments that interpolate a variable. The nginx documentation does not describe the script codes (ngx_http_script_complex_value_code) that a module reuses.
  • Affected: mruby_set and mruby_set_code with extra arguments, one or more of which interpolate a variable (two or more for mruby_set), when the module is built on nginx 1.31.3, 1.30.4 or 1.30.5. The documented [cache] form, a directive with no interpolated argument, and builds on any other nginx version are unaffected.
  • What to do: rebuild the module with this release; no configuration change is needed. If you build on nginx 1.31.3, 1.30.4 or 1.30.5 and a configuration uses such a directive, this release is required.

更新前に確認する挙動の変更

1. 変数を展開する引数を渡したmruby_setとmruby_set_codeで、workerプロセスが終わるか応答が返らない不具合を直しました(#921)

  • 変更前:nginx 1.31.3、1.30.4、1.30.5でビルドしたとき、追加の引数のうち1つ以上が変数を展開するmruby_setかmruby_set_codeのディレクティブでは、その変数を評価するときに、workerプロセスがsignal 11で終わるか、workerプロセスは終わらずに、リクエストに応答が返らないまま約75秒後に接続が切れました。後者のとき、curlはcurl: (52) Empty reply from serverを表示します。どちらになるかはメモリの配置で変わります。mruby_setでは追加の引数が2つ以上、mruby_set_codeでは1つ以上のときに、この経路を通ります。たとえばmruby_set $v script.rb "$host" "x";です。同梱のngx_devel_kitが、これらのnginxが必要とするend codeを出さずにnginxのcomplex valueのコードを出していたため、スクリプトのスタックが足りない状態になりました。これ以外のnginxでは、ngx_mrubyが固定している1.31.8と1.30.6を含めて、ディレクティブは動きましたが、評価した引数は、長さの予測で見積もった長さのままでした。この長さは、書き込んだバイト数より長いことがあります。ngx_mrubyのsetハンドラはその長さを読まないので、応答は変わりませんでした。
  • 変更後:end codeを持つnginxでは、同梱のngx_devel_kitがそれを追加します。end codeを持つのは、1.30.4以降の1.30.xと1.31.3以降で、freenginxは含みません。これにより、nginx 1.31.3、1.30.4、1.30.5でも、workerプロセスは終わらずに引数を評価し、応答を返します。end codeは、評価した引数を、実際に書き込んだ長さに詰めます。1.30.4より前、1.31.0から1.31.2、freenginxにはend codeが無いので、ガードはそれを出さず、ディレクティブはこれまでどおり動きます。nginx 1.31.8と1.30.6での応答は変わりません。引数が変数を展開しない、文書化された形式のmruby_set $v script.rb;とmruby_set $v script.rb cache;は、もともと影響を受けませんでした。
  • 変更の理由:
    • 不具合:mainlineのnginx 1.31.3とstableの1.30.4は、complex valueのスクリプトのスタックの更新を、新しいend codeに移しました。nginx commit a8289aa69c74です。同梱のngx_devel_kitは、ndk_http_rewrite_valueでcomplex valueのコードを再利用していますが、そのend codeを出していなかったため、スタックが足りない状態になり、変数を評価するときに、workerプロセスが終わるか、リクエストに応答が返らなくなっていました。mainlineのnginx 1.31.4とstableの1.30.6は、complex valueのコードでスタックの更新を元に戻し、end codeを出さないモジュールでは、結果の文字列が予測の長さを保つ形に変えました。この長さは、書き込んだバイト数より長いことがあります。nginx commit 4b90ec769235とPR #1601です。nginxはこれをstableの1.30.6で、スクリプトのコードを使うサードパーティのモジュール向けの修正として入れ、その問題が1.30.4から現れたと変更履歴に記しています。そのため、1.30.4と1.30.5のstableリリースが影響を受け、1.30.6は影響を受けません。
    • 前の挙動を残せなかった理由:nginx 1.31.3、1.30.4、1.30.5では、workerプロセスが終わるか、リクエストに応答が返らないので、このディレクティブを使えませんでした。nginx自身のrewriteモジュールと同じようにend codeを出せば、引数を評価でき、結果の文字列も書き込んだ長さになります。
    • ドキュメントが示していた挙動:2.7.18のmruby_setとmruby_set_codeは、mruby_set $VARNAME /PATH/TO/SCRIPT.rb [cache];とmruby_set_code $VARNAME 'CODE';を説明していて、変数を展開する追加の引数については何も書いていません。モジュールが再利用するスクリプトのコード(ngx_http_script_complex_value_code)は、nginxのドキュメントに説明がありません。
  • 影響の範囲:追加の引数のうち1つ以上が変数を展開するmruby_setとmruby_set_codeを、nginx 1.31.3、1.30.4、1.30.5でビルドした場合です。mruby_setでは追加の引数が2つ以上、mruby_set_codeでは1つ以上のときが対象です。文書化された[cache]の形式、変数を展開する引数が無いディレクティブ、これ以外のnginxでのビルドは、影響を受けません。
  • 必要な対応:このリリースでモジュールをビルドし直してください。設定の変更は要りません。nginx 1.31.3、1.30.4、1.30.5でビルドし、そのようなディレクティブを使う設定では、このリリースが必要です。