ngx_mruby v2.7.9
Behavior changes: read before upgrading
Section titled “Behavior changes: read before upgrading”The upstream methods raise ArgumentError on an object whose initialize raised and on a copy made with dup or clone, instead of returning nil or ending the worker (#816, #819)
Section titled “The upstream methods raise ArgumentError on an object whose initialize raised and on a copy made with dup or clone, instead of returning nil or ending the worker (#816, #819)”- Before:
Nginx::Upstream#initializeandNginx::Stream::Connection#initializegave the object its upstream before they checked that an upstream had the name, and the upstream methods read it without a check. A script could keep such an object afterinitializeraised: an object fromallocatewhoseinitializeraised, an object on which the script calledinitializeagain (withsend) and that call raised, or the object of a subclass whoseinitializerescued the exception ofsuper. An object fromallocatethat never got aninitializewas in the same state. When no upstream had the name,Nginx::Upstream#serverandNginx::Stream::Connection#upstream_serverreturnednil, andNginx::Upstream#server=,#keepalive_cache,#keepalive_cache=andNginx::Stream::Connection#upstream_server=read through a NULL pointer, and the worker process ended with a segmentation fault. When the upstream had more than one server, and on an object fromallocate, every one of these methods,#serverand#upstream_serverincluded, ended the worker in the same way. A copy thatduporclonemade of an object, also of one that.newreturned, had no upstream either: when mruby copies a data object (RData), it copies the instance variables and not the data. Each of these methods on such a copy ended the worker with a segmentation fault, and the request or session got no response (#819). - Now:
initializegives the object its upstream only when it found the upstream and its server. On an object without an upstream,Nginx::Upstream#server,#server=,#keepalive_cacheand#keepalive_cache=raiseArgumentError(uninitialized Nginx::Upstream), andNginx::Stream::Connection#upstream_serverand#upstream_server=raiseArgumentError(uninitialized Nginx::Stream::Connection). The exception ends the handler like any other exception of the script: arescuein the script catches it, and otherwise ngx_mruby logs it, the request gets 500, and the stream session is closed. The worker goes on to serve the next request and session. Aninitializethat succeeds after one that raised gives the object its upstream, and the methods work again. A copy made withduporclonehas no upstream, and the methods raise on it in the same way; the original object keeps its upstream (#819). - Why it changed:
- The defect:
initializestored the context of the object (the upstream, its peers and its server) before it checked them, and freed the old context and raised before it stored a new one for an upstream with more than one server; the methods read that context without checking that it held an upstream (#816). - Why the old behavior could not be kept: an object without an upstream has no server to return, change or keep connections for.
nilfrom#serverwas the result of reading an empty context, not a value that the method defined, and the next method on the same object ended the worker, which also ended the other requests that the worker was serving. Raising for every upstream method is the one behavior that the methods can have on such an object.ArgumentErrorwithuninitializedand the name is what the bundled mruby raises for its own objects whoseinitializedid not run, such asTime(uninitialized time) andRange(uninitialized range). - What the documentation promised: Nginx::
Upstream and Nginx::#new Stream:: in 2.7.8 said that the method raisesConnection #new RuntimeErrorwhen no upstream has the name, and said nothing about the object afterwards.
- The defect:
- Affected: scripts that keep using an
Nginx::UpstreamorNginx::Stream::Connectionobject after itsinitializeraised, an object fromallocate, or a copy thatduporclonemade of any object of these classes (#819), and call#server,#server=,#keepalive_cache,#keepalive_cache=,#upstream_serveror#upstream_server=on it. An object thatNginx::Upstream.neworNginx::Stream::Connection.newreturned behaves as before (its copies do not), and the methods ofNginx::Stream::Connectionthat do not use the upstream, such as#remote_ipand#stream_status, are not affected. - What to do: create the object with
Nginx::Upstream.neworNginx::Stream::Connection.new, and do not use it when the call raises; to use another upstream, create another object. Do not copy the object withduporclone: where a script needs a second object for the same upstream, create it with.new(#819). Code that called these methods on an object without an upstream gotnilor ended the worker on 2.7.8.
Nginx.module_version and the startup line of error.log give 2.7.9, the version of the release, instead of 2.7.1 (#822)
Section titled “Nginx.module_version and the startup line of error.log give 2.7.9, the version of the release, instead of 2.7.1 (#822)”- Before: on 2.7.2 to 2.7.8,
Nginx.module_versionreturned2.7.1, and when nginx read a configuration with anhttp {}block it logged a line at levelnoticeinerror.logthat starts withngx_mruby/2.7.1 (mruby/3.3.0) mechanism enabled(nginx addsin <file>:<line>of the configuration after it). - Now:
Nginx.module_versionreturns2.7.9, and the line inerror.logstarts withngx_mruby/2.7.9 (mruby/3.3.0) mechanism enabled. Each later release gives its own version: the suite fails when the version in the module differs from the newest release file indocs/releases/. - Why it changed:
- The defect: both read
MODULE_VERSIONinsrc/http/ngx_http_mruby_module.h, which was set to2.7.1for that release and was not changed in the seven releases after it. The release procedure indocs/releases/README.mdneither set the value nor checked it (#822). - Why the old behavior could not be kept: the value names the release that the module was built from. On 2.7.2 to 2.7.8 it named 2.7.1, whose fixes and behavior differ from those releases, so a script or a monitor that read it could not tell those releases from 2.7.1 or from one another. Keeping
2.7.1would have given 2.7.9 the same wrong value. - What the documentation promised: “Upgrading” in v2.7.1.md said that
Nginx.module_versionreturns2.7.1, the version of that release. Nginx.module_version in 2.7.8 said that the method returns the ngx_mruby version, with0.0.1as the example. The release notes of 2.7.2 to 2.7.8 said nothing about the value.
- The defect: both read
- Affected: scripts that compare the string that
Nginx.module_versionreturns, for example with2.7.1or to choose code by version, and monitoring that reads the line oferror.logthat starts withngx_mruby/and containsmechanism enabled. The value does not tell 2.7.2 to 2.7.8 apart: each of them gives2.7.1. - What to do: where a script or a monitor compares this value with
2.7.1, compare it with2.7.9, or with the version of the release that you run. To tell 2.7.2 to 2.7.8 apart, use the release tag or the commit that the module was built from, not this value.
New features
Section titled “New features”None.
Nginx::Upstream#server,#server=,#keepalive_cache,#keepalive_cache=andNginx::Stream::Connection#upstream_serverand#upstream_server=raiseArgumentErroron an object whoseinitializeraised, that came fromallocate, or thatduporclonemade. Before, they returnednilor read through a NULL pointer and ended the worker process (#816, #819)Nginx::Upstream.newandNginx::Stream::Connection.newfree the memory of the new object’s context when they raise for an upstream with more than one server. Before, each such call left that memory allocated until the worker exited (#816)
Build and test changes
Section titled “Build and test changes”- New test case:
test/t/cases/upstream_uninitialized.rb, with the server oftest/conf/conf.d/97-upstream-uninitialized.confon port 18093 and the stream server oftest/conf/conf.d/stream/53-upstream-uninitialized.confon port 12397 (#816) test/t/cases/upstream_uninitialized.rbalso calls the upstream methods on copies made withdupandcloneof an object that.newreturned, on the HTTP and stream servers of the existing cases, checks that they raiseArgumentError, and checks that the original object keeps its upstream (#819)- The server of
test/conf/conf.d/96-argument-types.conf, whichtest/t/cases/argument_types.rbtests, moved from port 18200 to 18092, the port it has onnext. A new test case takes a port that is free on bothmasterandnext, from 18080 to 18199 for HTTP and from 12345 to 12399 for stream;AGENTS.mdanddocs/test/README.mdsay so (#819) worker_connectionsof the test nginx (test/conf/nginx.conf) is 1024 instead of 200, the value ofnext. nginx counts each listening socket as one of the worker’s connections. The test nginx ofmasterlistens on 89 sockets (87 TCP and 2 UDP) and passes with 200; that ofnextlistens on 125, and under valgrind the connections thattest/t/cases/_wait_for_listen.rbopens to each port at the start used up the rest of the 200. With the same value, the line no longer differs between the branches (#819)test/t/cases/module_and_request.rbchecks thatMODULE_VERSIONinsrc/http/ngx_http_mruby_module.his the newest version among the filesdocs/releases/vX.Y.Z.md, compared as numbers. The pull request that creates the release file of a new version setsMODULE_VERSIONto that version in the same pull request; otherwise the suite fails (#822)
Upgrading
Section titled “Upgrading”- No directive was added, renamed or removed. Rebuild the module with this
release the way you built 2.7.8, and replace the binary or the dynamic
module as usual.
Nginx.module_versionreturns2.7.9.
Check these before upgrading. Each line is the “What to do” of its entry above.
- Scripts that keep using an
Nginx::UpstreamorNginx::Stream::Connectionobject after itsinitializeraised, or that use a copy made withduporclone: create the object with.new, and do not use it when the call raises; create a second object with.newinstead of a copy. - Scripts and monitoring that compare
Nginx.module_version, or the line oferror.logthat starts withngx_mruby/and containsmechanism enabled, with2.7.1: compare with2.7.9, or with the version of the release that you run; tell 2.7.2 to 2.7.8 apart by the release tag or the commit, not by this value.