Skip to content

v2.7.17

Latest

Choose a tag to compare

@matsumotory matsumotory released this 01 Dec 05:20
407c429

Behavior changes: read before upgrading

least_time header inflight counts the time of the header in an upstream block with mruby_upstream_keepalive

  • Before: with nginx 1.31 built with --with-http_ssl_module, nginx did not count the time to receive the header of a response for the servers of an upstream {} block with least_time header inflight and mruby_upstream_keepalive. When requests came one after another to two servers, the one that sends its header after a second got as many of them as the one that answers at once.
  • Now: nginx counts that time, and prefers the server with the least time, as it does with its own keepalive directive.
  • Why it changed:
    • The defect: least_time header inflight takes the time of the header from the call that nginx makes to the peer of an upstream when the header of a response has arrived (peer.notify). mruby_upstream_keepalive puts functions of its own in the place of those of the peer and had none for this call, so least_time did not count the time.
    • Why the old behavior could not be kept: the same call is what requests need that got no response (the first entry of "Fixes" in the release notes). Once mruby_upstream_keepalive passes it on, least_time counts the time.
    • What the documentation promised: nginx's documentation of least_time says that a request is passed to the server with the least average response time and the least number of active connections, and that with the parameter header the time to receive the response header is used. mruby_upstream_keepalive is documented as the same as nginx's keepalive, with which nginx counts the time.
  • Affected: upstream {} blocks with least_time header inflight and, after it, mruby_upstream_keepalive, in nginx 1.31 built with --with-http_ssl_module. least_time without inflight or with last_byte does not use the call and is the same as before.
  • What to do: nothing where the block is meant to prefer the faster server. A block that should not take the time of the header into account needs another load balancing method, for example least_conn.

mruby_upstream_keepalive does not keep an upstream connection whose request body was not fully sent

  • Before: an upstream {} block with mruby_upstream_keepalive kept an upstream connection in its pool, to reuse for a later request, even when nginx had sent the response before it finished sending the request body to that upstream.
  • Now: mruby_upstream_keepalive closes such a connection instead of keeping it, as nginx's own keepalive directive does.
  • Why it changed:
    • The defect: an upstream connection whose request body nginx had not finished sending was kept and reused for a later request. When it was reused, the upstream could read bytes of the earlier request's body as the beginning of the later request, which may come from a different client; GHSA-qq6c-wv62-6wjh has the details.
    • Why the old behavior could not be kept: nginx's keepalive does not keep such a connection, so the fix closes it the same way; nginx's keepalive has closed it since nginx 1.9.10.
    • What the documentation promised: mruby_upstream_keepalive is documented as the same as nginx's keepalive, which does not keep such a connection (nginx's keepalive).
  • Affected: upstream {} blocks with mruby_upstream_keepalive whose upstream sends the response before nginx finishes sending the request body. A block whose upstream reads the whole body before it responds, or closes the connection, is unchanged.
  • What to do: nothing; rebuild with this release.

mruby_upstream_keepalive does not keep an upstream connection it cannot shut down in a module built without SSL

  • Before: a module built with --with-compat and without --with-http_ssl_module, loaded into an nginx that has SSL, kept an upstream connection of an https upstream of a block with mruby_upstream_keepalive in its pool, to reuse for a later request, although it could not shut that connection's SSL down when it later closed it.
  • Now: mruby_upstream_keepalive does not keep such a connection in such a build; nginx opens a new connection to the https upstream for each request and closes each one, with its SSL object, itself. A module built with the same SSL options as nginx is unchanged.
  • Why it changed:
    • The defect: in a module built without SSL, a cached https upstream connection was closed without its SSL being shut down. This release also lets such a build answer the https upstream requests of a block with mruby_upstream_keepalive (the second entry under "Fixes" in the release notes), so these connections reach the cache.
    • Why the old behavior could not be kept: a module built without SSL cannot call ngx_ssl_shutdown, so it cannot shut such a connection down itself; by not keeping it, it leaves the close to nginx, which does.
    • What the documentation promised: mruby_upstream_keepalive is documented as the same as nginx's keepalive; nginx's own keepalive shuts an SSL connection down when it closes it.
  • Affected: a module built with --with-compat and without --with-http_ssl_module and loaded into an nginx that has SSL, with an https upstream of a block with mruby_upstream_keepalive. A build where nginx and the module have the same SSL options is unchanged.
  • What to do: nothing; rebuild with this release. To reuse TLS connections to an https upstream, build the module with --with-http_ssl_module.

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

mruby_upstream_keepaliveのあるupstreamブロックで、least_time header inflightがレスポンスのヘッダを受け取るまでの時間を集計する

  • 変更前:--with-http_ssl_module付きでビルドしたnginx 1.31では、least_time header inflightとmruby_upstream_keepaliveのあるupstream {}ブロックのサーバーについて、レスポンスのヘッダを受け取るまでの時間を、nginxが集計していませんでした。サーバーが2台のブロックにリクエストが1つずつ順に届くと、ヘッダを1秒後に送るサーバーにも、すぐに応答するサーバーと同じ数のリクエストを渡していました。
  • 変更後:nginxは、その時間を集計し、時間が最も短いサーバーを優先します。nginx自身のkeepaliveディレクティブを使うときと同じ動作です。
  • 変更の理由:
    • 不具合:least_time header inflightは、レスポンスのヘッダが届いたときにnginxがupstreamのピアに対して行う呼び出し(peer.notify)で、この時間を集計します。mruby_upstream_keepaliveは、ピアの関数を自分の関数に差し替えますが、この呼び出しに対応する関数を用意していませんでした。そのため、least_timeは時間を集計しませんでした。
    • 前の挙動を残せなかった理由:リリースノートの「不具合の修正」の最初の項目にある、レスポンスが返らない不具合を直すには、mruby_upstream_keepaliveが、この呼び出しを、それを使うモジュールに渡す必要があります。渡すと、least_timeも時間を集計します。
    • ドキュメントが示していた挙動:nginxのleast_timeのドキュメントには、平均の応答時間が最も短く、アクティブな接続の数が最も少ないサーバーにリクエストを渡し、パラメータがheaderのときはレスポンスのヘッダを受け取るまでの時間を使う、とあります。mruby_upstream_keepaliveは、ドキュメントでは、nginxのkeepaliveと同じとされています。keepaliveを使うブロックでは、nginxはこの時間を集計します。
  • 影響の範囲:--with-http_ssl_module付きでビルドしたnginx 1.31で、least_time header inflightと、その後に書いたmruby_upstream_keepaliveがあるupstream {}ブロックです。inflightの無いleast_timeと、last_byteを指定したleast_timeは、peer.notifyの呼び出しを使わないので、前と同じです。
  • 必要な対応:速いサーバーを優先するためのブロックでは、対応は要りません。ヘッダを受け取るまでの時間をサーバーの選択に使いたくないブロックでは、least_connなどの別の負荷分散の方式に変えてください。

mruby_upstream_keepaliveは、リクエストの本文を送り切っていない接続を保持しない

  • 変更前:mruby_upstream_keepaliveのあるupstream {}ブロックは、nginxがリクエストの本文をupstreamへ送り切る前にレスポンスを返した接続でも、後続のリクエストで使い回すために、プールに保持していました。
  • 変更後:mruby_upstream_keepaliveは、その接続を保持せず閉じます。nginx自身のkeepaliveディレクティブと同じ動作です。
  • 変更の理由:
    • 不具合:nginxが本文を送り切っていない接続を、保持して後続のリクエストで使い回していました。使い回すと、upstreamが、前のリクエストの送り切られなかった本文のバイトを、後続のリクエストの先頭として読むことがありました。後続のリクエストは、別のクライアントのものであることもあります。詳細はGHSA-qq6c-wv62-6wjhにあります。
    • 前の挙動を残せなかった理由:nginxのkeepaliveは、このような接続を保持しないので、修正でも同じように閉じます。nginxのkeepaliveは、nginx 1.9.10以降、このように閉じています。
    • ドキュメントが示していた挙動:mruby_upstream_keepaliveは、ドキュメントでは、nginxのkeepaliveと同じとされています。nginxのkeepaliveは、このような接続を保持しません(nginxのkeepalive)。
  • 影響の範囲:mruby_upstream_keepaliveのあるupstream {}ブロックで、upstreamが、nginxがリクエストの本文を送り切る前にレスポンスを返す場合です。upstreamが本文を全部読んでから応答するブロックや、接続を閉じるブロックは、前と同じです。
  • 必要な対応:ありません。このリリースでモジュールをビルドし直してください。

mruby_upstream_keepaliveは、SSL無しでビルドしたモジュールでは、閉じられない接続を保持しない

  • 変更前:--with-compat付き、--with-http_ssl_module無しでビルドしたモジュールを、SSL付きのnginxで使うとき、mruby_upstream_keepaliveのあるブロックのhttpsのupstreamの接続を、後続のリクエストで使い回すためにプールに保持していました。しかし、後でその接続を閉じるときに、接続のSSLをシャットダウンできませんでした。
  • 変更後:このビルドでは、mruby_upstream_keepaliveはその接続を保持しません。nginxが、httpsのupstreamへの接続をリクエストごとに新しく開き、SSLオブジェクトも含めて自分で閉じます。nginxとモジュールを同じSSLのオプションでビルドしているときは、前と同じです。
  • 変更の理由:
    • 不具合:SSL無しでビルドしたモジュールで、キャッシュしたhttpsのupstreamの接続を、SSLをシャットダウンせずに閉じていました。このリリースでは、このビルドでもmruby_upstream_keepaliveのあるブロックのhttpsのupstreamのリクエストに応答するようになる(リリースノートの「不具合の修正」の2つ目の項目)ので、これらの接続がキャッシュに入ります。
    • 前の挙動を残せなかった理由:SSL無しでビルドしたモジュールは、ngx_ssl_shutdownを呼べないので、このような接続を自分で閉じられません。接続を保持しないことで、閉じる処理をnginxに任せ、nginxがSSLをシャットダウンします。
    • ドキュメントが示していた挙動:mruby_upstream_keepaliveは、ドキュメントでは、nginxのkeepaliveと同じとされています。nginx自身のkeepaliveは、SSLの接続を閉じるときにSSLをシャットダウンします。
  • 影響の範囲:--with-compat付き、--with-http_ssl_module無しでビルドしたモジュールを、SSL付きのnginxで使い、mruby_upstream_keepaliveのあるブロックにhttpsのupstreamがある場合です。nginxとモジュールを同じSSLのオプションでビルドしているときは、前と同じです。
  • 必要な対応:ありません。このリリースでモジュールをビルドし直してください。httpsのupstreamへのTLS接続を使い回すには、--with-http_ssl_module付きでモジュールをビルドしてください。