ngx_mruby v3.0.0
Behavior changes: read before upgrading
Section titled “Behavior changes: read before upgrading”The local start example binds to loopback and adds mock model routing (#672)
Section titled “The local start example binds to loopback and adds mock model routing (#672)”- Before:
examples/start/compose.yamlpublished host port 8080 on all interfaces, and the trial demonstrated only the/helloRuby handler. - Now: the host binding is
127.0.0.1:8080:8080. The trial retains/helloand adds/v1/responses, which checks a public demonstration key and selects one of two loopback mock endpoints by model. The bilingual walkthrough checks route selection, credential replacement, rejected requests, editing, restoration and reload. - Why it changed:
- The reason: the first exercise should demonstrate the model-routing use case without a provider account or real key.
- Why the old behavior could not be kept: exposing the trial on every host interface is unnecessary for a local-only exercise;
/helloremains available. - What the documentation promised: the earlier start page showed a Hello response and explained that the host port was broadly published.
- Affected: users running the development example from
examples/start/; no runtime API or stable 2.x configuration is changed. - What to do: run the updated walkthrough locally. The bundled keys are demonstration values, and the mock response is not LLM inference, a provider compatibility test or API-format conversion. Do not publish this trial as a service.
The bundled mruby is 4.1.0-rc2 instead of 3.3.0 (#561, #678)
Section titled “The bundled mruby is 4.1.0-rc2 instead of 3.3.0 (#561, #678)”- Before: ngx_mruby 2.x bundles mruby 3.3.0 and builds the core gems that
full-core.gemboxof mruby 3.3.0 selects, mruby-print included. - Now: this release bundles mruby 4.1.0-rc2, a release candidate of 4.1.0: the tag
4.1.0-rc2of mruby (commitc17ffcc24190, 2026-09-11), whoseMRUBY_VERSIONis4.1.0. The defaultbuild_config.rbtakes the core gems thatNGX_MRUBY_CORE_GEMSnames: the set thatfull-core.gemboxof mruby 3.3.0 selected, without mruby-print (mruby 3.4 removed it;Kernel#print,#putsand#pcome from mruby-io). It leaves out these core gems, whichfull-core.gemboxof 4.1.0-rc2 takes: mruby-task, mruby-encoding, mruby-strftime (Time#strftime) and mruby-benchmark (Benchmark), and three of the gems that are new in 4.1, mruby-regexp, mruby-string-bitops and mruby-bin-mrb. It takes the other three new gems, mruby-env, mruby-process and mruby-signal, which defineENV,ProcessandSignal(see the entries ofENVandProcessbelow, #766).Regexpstill comes from the third-party gem mattn/mruby-onig-regexp. It keeps mruby-sleep, whichfull-core.gemboxleaves out. mruby 4.1 compiles Ruby code with Prism. The line that nginx logs at theinfolevel when it reads the configuration ends in(mruby/4.1.0) mechanism enabled. The entries below list the differences that scripts, log monitoring, C extensions and builds see, as far as they were found and measured for ngx_mruby: they are not a complete list of the changes between mruby 3.3.0 and 4.1.0-rc2. mruby lists its user-visible changes indoc/mruby3.4.md,doc/mruby4.0.mdand, for 4.1,NEWS.md. The cost per request, measured for ngx_mruby against the bundled mruby 4.0.0 (the callgrind lane, user-space instructions of nginx per request, 2026-10-31, #678): inauth(a server rewrite handler with two Hash lookups and three variable assignments, then a proxy), 44228 → 52761 instructions, 42599 → 45621 without the GC; inheaders, 30040 → 34903, and 28044 → 27612 without the GC. At 3 GHz and 1 to 2 instructions per cycle, an instruction takes 0.17 to 0.33 ns, soauthtakes about 7.4 to 14.7 µs of CPU per request with 4.0.0 and 8.8 to 17.6 µs with 4.1.0-rc2 (+1.4 to +2.8 µs), and at 10,000 requests per second it uses 8.8% to 17.6% of a core instead of 7.4% to 14.7%. The GC runs more often and does more each time: inauth, 12.2 → 24.4 GC calls per 1000 requests, 134,000 → 293,000 instructions per call. mruby 4.1 runs a full GC instead of adding a heap page when its last mark left room (mruby commit c009f1633, which bounds the heap of small targets), and its VM spends more instructions on the same bytecode (“Known differences” under “Performance comparison with callgrind” in docs/test/README.md). - Why it changed:
- The reason: the v3 plan puts stability, performance and current dependencies before new capabilities, and mruby publishes no maintenance releases of 3.x (
docs/proposals/v3-plan.md, sections 3.3 and 6). Decision 1 of the plan (section 7) sets mruby 4.1.0 as the mruby of v3, because 4.1 counts the registrations ofmrb_gc_register(): a secondmrb_gc_unregister()of an object no longer drops the registration of another owner (mruby/mruby#7277), andNginx::Asyncregisters its fibers this way. The owner chose on 2026-10-29 to bundle 4.1.0-rc2 instead of waiting for the tag4.1.0;nextmoves to 4.1.0 when it is tagged. 4.1.0-rc2 has the fix of mruby/mruby#7032 (commitc6866eed4). - Why the old behavior could not be kept: mruby 3.3.0 gets no more fixes. The
NEWS.mdof 4.1 alone has 20 entries under “Security Fixes” since 4.0, among them a use-after-free inString#lstrip!,#rstrip!and#strip!and one in the incremental GC; keeping 3.3.0 would have kept such defects in every worker. - What the documentation promised: the documentation of 2.x said nothing about which version of mruby a later release bundles. docs/install/README.md of 2.7.0 lists the default mrbgems as “mruby/mruby default mrbgems” without a version.
- The reason: the v3 plan puts stability, performance and current dependencies before new capabilities, and mruby publishes no maintenance releases of 3.x (
- Affected: every build of the module, and every Ruby script that it runs.
- What to do: rebuild the module together with the bundled mruby, then check the entries below and, for the changes that they do not cover, mruby’s three lists; Migrating from ngx_mruby 2.x to 3.0.0 has the steps. ngx_mruby keeps mruby’s GC defaults:
GC.interval_ratiodid not change the GC share, and a larger heap lowered it but raised the work without the GC.
A build_config.rb of your own needs the core gem changes of mruby 4.1 (#561, #678)
Section titled “A build_config.rb of your own needs the core gem changes of mruby 4.1 (#561, #678)”- Before: a
build_config.rbof your own could name mruby-print, or takefull-core.gemboxand get the core gems of mruby 3.3.0, mruby-sleep included. - Now: mruby 4.1.0-rc2 has no mruby-print and no hal-* gems, and
ngx_mruby_core_gemsinbuild_config.rbstops the build on a name that the bundled mruby does not have. A list written for mruby 4.0.0 that names hal-posix-io, hal-posix-dir and hal-posix-socket stops there too: in 4.1 the POSIX back ends are part of mruby-io, mruby-dir and mruby-socket.full-core.gemboxof 4.1.0-rc2 takes mruby-task, which redefinesKernel#sleep, arms a SIGALRM interval timer (setitimer) in every process that opens an mrb_state and allows at most 8 mrb_states (MRB_TASK_MAX_VMS), and mruby-encoding (see the entry ofString#valid_encoding?), and leaves out mruby-sleep. It also takes mruby-env, mruby-process and mruby-regexp, which defineENV,ProcessandRegexp, the classes that iij/mruby-env, iij/mruby-process and mattn/mruby-onig-regexp define; the two gems of iij have the same names as these core gems.for_windows?inmruby/lib/mruby/gem.rbtreats a one-letter directory at the root as a Windows drive: a 4.0.0 build whose work directory was mounted at/sin a container chose the Windows back ends by itself and stopped atwindows.h: No such file or directory, and thefor_windows?of 4.1.0-rc2 makes the same test (read from the source, not measured). - Why it changed:
- The reason: these are changes of mruby 3.4, 4.0 and 4.1 that come with the bundled mruby (see the entry above).
- Why the old behavior could not be kept: a core gem that the bundled mruby no longer has cannot be built, and
ngx_mruby_core_gemsstops on such a name on purpose, so that an update of mruby cannot drop a gem from the list unnoticed. - What the documentation promised: docs/install/README.md of 2.7.0 lists “mruby/mruby default mrbgems” and says nothing about core gems in a
build_config.rbof your own.
- Affected: builds with a
build_config.rbother than the one of this release that name mruby-print or the hal-* gems, or takefull-core.gembox. - What to do: start from the
build_config.rbof this release, or select the core gems by name asNGX_MRUBY_CORE_GEMSdoes: remove mruby-print, hal-posix-io, hal-posix-dir and hal-posix-socket, and decide on mruby-task and mruby-encoding as Core gems describes. A build that takesfull-core.gemboxand also iij/mruby-env, iij/mruby-process or mattn/mruby-onig-regexp chooses between them and the core gems mruby-env, mruby-process and mruby-regexp.
Building the bundled mruby needs Ruby 3.0 or later (#678)
Section titled “Building the bundled mruby needs Ruby 3.0 or later (#678)”- Before: the rake of mruby 3.3.0, which 2.x bundles, builds with Ruby 2.x: its
mrbcbuilds with Ruby 2.6.10 (the Ruby of macOS). - Now: the rake of mruby 4.1.0-rc2 stops while it links
mrbcwhen it runs on Ruby 2.6.10, withArgumentError: unknown keywords: flags, flags_before_libraries, flags_after_libraries, libs, outfile, objs(mruby/lib/mruby/build/command.rb, line 47). It builds with Ruby 3.0.2 (Ubuntu 22.04, the Ruby of CI and of the test container) and with Ruby 4.0.5.Command::Linker#runpasses the parameters of the link as a Hash to_run(options, params={}, chdir: nil), and a Ruby before 3.0 reads a last Hash with Symbol keys as keyword arguments when the method takes keywords. Ruby 2.7 was not measured; by that rule it stops in the same way. mruby’s owndoc/guides/compile.mdstill says “Ruby 2.5 or later”. - Why it changed:
- The reason: the build of mruby 4.1 changed (see “The bundled mruby is 4.1.0-rc2 instead of 3.3.0”); this release bundles mruby 4.1.0-rc2.
- Why the old behavior could not be kept: keeping Ruby 2.x would have meant changing
mruby/, which ngx_mruby updates only from mruby’s own tree. - What the documentation promised: docs/install/README.md of 2.7.0 asks for Ruby with rake and names no version.
- Affected: builds that run on Ruby 2.x, for example the
rubypackage of Ubuntu 20.04 (2.7) or the Ruby of macOS (2.6). - What to do: build with Ruby 3.0 or later; for a version-managed Ruby, put its
bindirectory onPATHbefore the build.
The third-party mrbgems are built at the commits that build_config.rb.lock records (#558)
Section titled “The third-party mrbgems are built at the commits that build_config.rb.lock records (#558)”- Before:
build_config.rbnames the third-party mrbgems without a commit, and.gitignorelists thebuild_config.rb.lockthat mruby’s rake writes, so the lock stays out of the repository. A build from a new checkout or a source archive clones the head of each gem’s branch withgit clone --depth 1, so two builds of the same ngx_mruby commit made on different days can get different gem code. - Now:
build_config.rb.lockis committed. It records a commit for each third-party gem of the default build and for each gem that those depend on, for example ksss/mruby-stringio, which the bundled rack-based-api needs. A build from a new checkout or a source archive clones each of them with its whole history and checks the recorded commit out, so every build of an ngx_mruby commit gets the same gem code. A gem that abuild_config.rbof your own adds is cloned at the head of its branch, and rake adds its entry to the lock in your tree, whichgit statusthen shows as modified. rake does not fetch into a clone that exists: after a change of the lock, a build in a tree that keepsmruby/buildstops withfatal: reference is not a treewhen a clone does not have the new commit. symisc/vedis, which matsumotory/mruby-vedis clones by itself, is not pinned. - Why it changed:
- The reason: the v3 plan pins every third-party gem by commit and commits
build_config.rb.lock, so that the same tag builds the same binary (docs/proposals/v3-plan.md, section 4, Pillar A). - Why the old behavior could not be kept: without the pins, the gem code of a build depends on the day of the build. A change in any of the gem repositories reaches every later build of a released tag, and every CI run, without a change in ngx_mruby.
- What the documentation promised: the documentation of 2.x said nothing about the commits of the third-party gems. docs/install/README.md lists the default mrbgems by name only.
- The reason: the v3 plan pins every third-party gem by commit and commits
- Affected: builds from source that expect the newest commits of the third-party gems,
build_config.rbfiles of your own that add gems, and trees that keepmruby/buildwhen the lock changes. - What to do: nothing for a new checkout or a source archive. To build a gem at another commit, change its entry in the lock as Gem commits describes. After a change of the lock, for example one that a pull brings in, remove
mruby/buildbefore the next build.
Hash#inspect and Hash#to_s use a new format (#561)
Section titled “Hash#inspect and Hash#to_s use a new format (#561)”- Before:
{"a"=>1}and{:a=>1}. - Now:
{"a" => 1}and{a: 1}(since mruby 3.4). Everything that prints a Hash with these methods changes with them: string interpolation ("#{h}"),sprintf("%s", h)andArray#inspect. - Affected: scripts that put the
inspectorto_sof a Hash into a response body or a header, or compare it with a fixed string. The test suite of ngx_mruby saw the change (/async_http_sub_requestintest/t/ngx_mruby.rb). - What to do: do not use the
inspectorto_sof a Hash as a data format, in a response body or in a header. Build the string yourself, or useJSON.generate.
Exception#inspect, and so the mrb_run failed lines of error.log, use a new format (#561)
Section titled “Exception#inspect, and so the mrb_run failed lines of error.log, use a new format (#561)”- Before:
boom (RuntimeError). ngx_mruby writes the exception of a script withException#inspectinto themrb_run failedlines oferror.log(levelerror; the line that an exception inmruby_stream_server_context_codelogs while nginx reads the configuration,mrb_run failed: ngx_mruby stream module configuration failed: error: ..., is at levelemerg), for examplemrb_run failed: return 500 HTTP status code to client: error: boom (RuntimeError). - Now:
#<RuntimeError: boom>, so the line ends inerror: #<RuntimeError: boom>.Exception#messageand#to_sare unchanged. - Affected: log parsers and alerts that match the old form, and scripts that use
Exception#inspect. The test suite of ngx_mruby saw the change inerror.log. - What to do: update log parsers and alerts that match the old form.
The messages logged while nginx reads the configuration are at the info level instead of notice (#565)
Section titled “The messages logged while nginx reads the configuration are at the info level instead of notice (#565)”- Before: while nginx reads the configuration, ngx_mruby logs these messages at the
noticelevel:ngx_mruby/<version> (mruby/<version>) mechanism enabled, once for thehttp {}block;ngx_mruby NOTICE ...: compile info: ...for each directive with Ruby code, andngx_mruby-stream-module NOTICE ...: compile info: ...for each one instream {}; andngx_mruby NOTICE ...: target variable=(...)for eachmruby_setandmruby_set_code. nginx writes what it logs while it reads the configuration to its startup log, at thenoticelevel whatevererror_logsays, so every start of nginx writes these lines, also witherror_log ... warn;. - Now: the same messages are logged at the
infolevel, and their text saysINFOinstead ofNOTICE(ngx_mruby INFO ...,ngx_mruby-stream-module INFO ...). A start of nginx writes none of them.nginx -twrites them at[info]to the startup log only: nginx copies a line of the startup log to the terminal only atwarnand above, so the output ofnginx -tdoes not show them. A reload writes them to theerror_logof the running configuration when thaterror_logis atinfoordebug. Errors while nginx reads the configuration, such as a script file that cannot be opened, are still logged atemerg. - Why it changed:
- The defect: every start of nginx wrote these lines, and an
error_logat a level abovenoticedid not stop them (#320). - Why the old behavior could not be kept: nginx writes what it logs while it reads the configuration to its startup log at the
noticelevel, before the configurederror_logtakes over, so noerror_logsetting filters a message atnotice. Only a level belownoticekeeps the lines out of a start. - What the documentation promised: the documentation of 2.x said nothing about these messages.
- The defect: every start of nginx wrote these lines, and an
- Affected: log monitoring and scripts that look for these lines when nginx starts, for example to see that the module is loaded.
- What to do: to see them, run
nginx -t -e stderr, which writes the startup log to the terminal; read the startup log afternginx -t; or reload witherror_logatinfo. The startup log is the file given with-e, or else the error log path compiled into nginx (logs/error.logunder the prefix by default), as Messages logged while nginx reads the configuration describes.
Nginx.module_version and the mechanism enabled line give 3.0.0 (#823)
Section titled “Nginx.module_version and the mechanism enabled line give 3.0.0 (#823)”- Before: on 2.7.1 to 2.7.8,
Nginx.module_versionreturned2.7.1; from 2.7.9 on, it returns the version of the 2.x release (v2.7.9.md). The line that ngx_mruby logs while nginx reads a configuration with anhttp {}block starts withngx_mruby/2.7.x (mruby/3.3.0) mechanism enabled, with the same value. - Now:
Nginx.module_versionreturns3.0.0, also in the alpha, beta and rc pre-releases of 3.0.0, and the line starts withngx_mruby/3.0.0 (mruby/4.1.0) mechanism enabled. The line is logged at theinfolevel, as the entry on the messages logged while nginx reads the configuration above describes (#565). - Why it changed:
- The reason: the value names the release that the module was built from.
MODULE_VERSIONinsrc/http/ngx_http_mruby_module.his set to the version of the newest release file indocs/releases/, and the suite fails when it is not (#822); onnextthat file isv3.0.0.mdfor the whole 3.0.0 cycle, so the value is3.0.0(#823). - Why the old behavior could not be kept: a 2.x value would make a 3.0.0 module name a 2.x release, whose behavior differs from 3.0.0 in every entry of this section, so a script or a monitor that reads the value could not tell the two apart.
- What the documentation promised: Nginx.module_version says that the method returns the ngx_mruby version, and v2.7.9.md says that each release from 2.7.9 on gives its own version.
- The reason: the value names the release that the module was built from.
- Affected: scripts that compare the string that
Nginx.module_versionreturns, for example to choose code by version, and monitoring that reads the line that starts withngx_mruby/and containsmechanism enabled. The pre-releases of 3.0.0 give3.0.0as well, so the value does not tell them from one another or from the release 3.0.0. - What to do: where a script or a monitor compares this value with a 2.x version, compare it with
3.0.0as well, or compare its first number. To tell a pre-release of 3.0.0 from another, or from the release, use the tag or the commit that the module was built from, not this value.
The message of NoMethodError names the class of the receiver (#561)
Section titled “The message of NoMethodError names the class of the receiver (#561)”- Before:
undefined method 'foo'. - Now:
undefined method 'foo' for NilClass. - Affected: scripts and log monitoring that match the message of a
NoMethodError. - What to do: match on the exception class, not on the message.
private and protected are enforced (#561, #678)
Section titled “private and protected are enforced (#561, #678)”- Before: not enforced: a method defined after
privateorprotected,initialize, a method defined withdefat the top level, and theKernelmethods could be called with an explicit receiver,Kernelitself included (Kernel.Integer("12")is12).Module#instance_methodsand#methodsof an object list private methods too: for a class with a methodpuband a private methodpriv,instance_methods(false)is[:priv, :pub]. - Now: enforced (since mruby 3.4): these methods raise
NoMethodError(private method '<name>' called for <class>) when called with an explicit receiver other thanself. This includes theKernelmethods such asraise,sprintf,puts,Integerandrandcalled on another object (1.Integer("3")raisesprivate method 'Integer' called for Integer), andinitialize_copy,respond_to_missing?andmethod_missing, which mruby 4 defines as private ("a".initialize_copy("b")raises). Called onKernelitself, the methods ofKernelwork as on 2.x (Kernel.Integer("12")is12; mruby 4.0.0 raisedNoMethodErrorthere, and 4.1 calls them again, mruby/mruby#6976). Aprotectedmethod can be called with an explicit receiver from a method of the same class, as in CRuby, and raisesNoMethodError(protected method '<name>' called for <class>) from anywhere else.respond_to?returnstruefor a private method on both versions, so it does not tell whether such a call works.Module#instance_methodsand#methodsof an object leave private methods out (instance_methods(false)of the class above is[:pub]);Module#private_instance_methodsand#private_methodslist them. In handler code, a method defined withdefat the top level stays public, so a call of it with an explicit receiver still works (the proposal for #502, section 1.4). - Why it changed:
- The reason: mruby 3.4 enforces the visibility of methods as CRuby does, and mruby 4.1 checks the receiver of a
protectedmethod against the class of the caller’sself(mruby/mruby#6975, commit 534efe0 in mruby’sNEWS.md); this release bundles mruby 4.1.0-rc2 (see “The bundled mruby is 4.1.0-rc2 instead of 3.3.0”). - Why the old behavior could not be kept: the VM of the bundled mruby checks the visibility; ngx_mruby has no option to turn the check off.
- What the documentation promised: the documentation of 2.x said nothing about the visibility of methods.
- The reason: mruby 3.4 enforces the visibility of methods as CRuby does, and mruby 4.1 checks the receiver of a
- Affected: scripts that call such a method with an explicit receiver other than
selfandKernel, and scripts that look for private methods in the result ofinstance_methodsormethods. - What to do: call them without a receiver, or with
send(obj.send(:name)works on both versions). To list private methods, useprivate_instance_methodsorprivate_methods.
Module#remove_const, #private, #public, #protected, #module_function and the hooks are private (#561)
Section titled “Module#remove_const, #private, #public, #protected, #module_function and the hooks are private (#561)”- Before: public:
Foo.remove_const(:X),M.included(Foo),M.prepended(Foo)andobj.singleton_method_added(:m)work. The hooks are#included,#extended,#prepended,#inheritedand#method_addedofModuleandClass, andBasicObject#singleton_method_added. - Now: private: called with an explicit receiver, they raise
NoMethodError: private method ... called.sendworks, and mruby still calls the hooks itself:prependcallsprepended, anddef obj.mcallssingleton_method_added. - Affected: scripts that call one of these methods with an explicit receiver.
- What to do: call them in the body of the class or module without a receiver, or with
send(Foo.send(:remove_const, :X)).
Overrides of append_features, prepend_features and extend_object are not called (#561)
Section titled “Overrides of append_features, prepend_features and extend_object are not called (#561)”- Before:
include,prependandextendcall these three methods, so a module can override them. - Now: the three methods are gone (
Module.new.respond_to?(:append_features, true)isfalse, and the same for the other two).include,prependandextendadd the module without calling them, so an override is skipped without an error. The hooksincluded,prependedandextendedare still called. - Affected: modules that override one of the three methods.
- What to do: move the code to
included,prependedorextended.
allbits?, anybits? and nobits? are methods of Integer only (#561)
Section titled “allbits?, anybits? and nobits? are methods of Integer only (#561)”- Before: methods of
Numeric, so they work on a Float (1.5.allbits?(1)istrue). - Now: methods of
Integeronly; on a Float they raiseNoMethodError. On an Integer they work as before (6.allbits?(2)istrue). - Affected: scripts that call them on a Float.
- What to do: convert a Float with
to_ifirst.
FileTest is a module (#561)
Section titled “FileTest is a module (#561)”- Before:
FileTestis a class. - Now:
FileTestis a module.FileTest.exist?and its other methods are called as before. - Affected: scripts that use
FileTestas a class, other than by calling its methods. - What to do: nothing for calls of its methods.
Assigning a constant in a method body is a SyntaxError (#561)
Section titled “Assigning a constant in a method body is a SyntaxError (#561)”- Before: allowed (
def m; X = 1; end). - Now:
SyntaxError(syntax error, dynamic constant assignment), when the script is compiled. - Affected: scripts that assign a constant inside a method body. The Rack-style
Kernel#runof ngx_mruby setsServerwithKernel.const_set. - What to do: use
Object.const_set(:X, 1)(orKernel.const_set).
"#@ivar", "#@@cvar" and "#$global" in a string interpolate the variable (#678)
Section titled “"#@ivar", "#@@cvar" and "#$global" in a string interpolate the variable (#678)”- Before: in a double-quoted string, a heredoc or a backquoted command,
#followed by@,@@or$and a name is plain text:@x = 5; "a#@x"is"a#@x". - Now: they interpolate the variable, as in CRuby:
"a#@x"is"a5","#$gv"is the value of$gv, and an instance variable that is not set gives an empty string ("a#@nope"is"a").#{...}works as before (since mruby 4.1, d4aad5d). - Why it changed:
- The reason: mruby 4.1 adds this form of interpolation (see “The bundled mruby is 4.1.0-rc2 instead of 3.3.0”), as CRuby has it.
- Why the old behavior could not be kept: the compiler of the bundled mruby reads the form; ngx_mruby has no option to turn it off.
- What the documentation promised: the documentation of 2.x said nothing about it.
- Affected: scripts whose double-quoted strings contain
#@,#@@or#$followed by a name, for example a text such as"Ticket #@id"or"price #$total"meant literally, also in response bodies and headers. - What to do: find such strings (see Scripts) and escape the
#("a\#@x") or use a single-quoted string ('a#@x'). The string is the same on both versions.
Syntax errors have the messages of Prism (#678)
Section titled “Syntax errors have the messages of Prism (#678)”- Before: the parser of mruby 3.3.0 gives messages such as
syntax error, unexpected end of fileanddynamic constant assignment. - Now: mruby 4.1 compiles with Prism, and a
SyntaxErrorhas its messages:eval("1 +")raisesSyntaxErrorwithsyntax error, unexpected end-of-input; expected an expression after the operator,eval("foo(")withsyntax error, unexpected end-of-input; expected a `)` to close the arguments, andeval("x = ")withsyntax error, expected an expression after `=`(measured with themrubycommand of the build). The messages that mruby reports when ngx_mruby compiles a script file or inline code that does not parse come from the same compiler. - Why it changed:
- The reason: mruby 4.1 replaced its parser generated from
parse.ywith Prism (NEWS.md, “the compiler is Prism”). - Why the old behavior could not be kept: the bundled mruby has no other compiler.
- What the documentation promised: the documentation of 2.x said nothing about the messages of syntax errors.
- The reason: mruby 4.1 replaced its parser generated from
- Affected: log monitoring and scripts that match the text of a syntax error, for example of
evalor of a script that nginx fails to load. - What to do: match on
SyntaxErrorand the file and line, not on the text aftersyntax error.
An Array, a Hash or a Struct that holds itself can be compared (#678)
Section titled “An Array, a Hash or a Struct that holds itself can be compared (#678)”- Before:
==andeql?of two arrays, hashes or structs that hold themselves recurse without end and raiseSystemStackError:a = []; a << a; b = []; b << b; a == braisesSystemStackError(stack level too deep). - Now: such a comparison works as in CRuby. A pair that is already being compared counts as equal, and the other elements decide:
a == babove istrue, and witha = [1]; a << a; b = [2]; b << b,a == bisfalse(since mruby 4.1, mruby/mruby#7425; measured with themrubycommand of mruby 3.3.0 and of the host build of this release). - Why it changed:
- The reason: mruby 4.1 changes
#==and#eql?ofArray,HashandStructfor containers that hold themselves (see “The bundled mruby is 4.1.0-rc2 instead of 3.3.0”). - Why the old behavior could not be kept: the bundled mruby has only the new methods; ngx_mruby has no option to bring the old ones back.
- What the documentation promised: the documentation of 2.x said nothing about it.
- The reason: mruby 4.1 changes
- Affected: scripts that compare containers that hold themselves and rescue the
SystemStackError. - What to do: nothing for most scripts. A script that relies on the
SystemStackErrorchecks for the container itself before the comparison.
Float values have no bit operations (#561)
Section titled “Float values have no bit operations (#561)”- Before:
~,&,|and^work on the integer part (1.5 & 1is1,~1.5is-2). For a shift count from 1 up,<<multiplies the Float by that power of two and truncates (1.5 << 1is3,-1.5 << 1is-3,1.5 << 40is1649267441664), and gives a Float when the result is outside the Integer range (1.5 << 70is1.77088743107612e+21). For a shift count from 1 to 32,>>divides a positive Float by that power of two and truncates (8.0 >> 1is4,1.5 >> 1is0), and returns-1for every negative Float (-8.0 >> 1is-1). For a count above 32,>>returns0for a positive and-1for a negative Float (1e20 >> 32is23283064365,1e20 >> 33is0). A count of 0 returns the Float unchanged (-1.5 >> 0is-1.5), and a negative count shifts the other way (1.5 >> -1is3). - Now:
~,&,|,^,>>and<<raiseNoMethodErroron a Float (mruby 3.4 removed all six). - Affected: scripts that apply one of the six operators to a Float.
- What to do: for
~,&,|and^, convert withto_ifirst. For<<and>>,to_ifirst can give another number (1.5.to_i << 1is2,-8.0.to_i >> 1is-4). Where the old number matters: for<<by a count from 1 up, multiply the Float by the power of two and callto_i; for>>by a count from 1 to 32, divide a positive Float by the power of two and callto_i, and use-1for a negative Float; for>>by a count above 32, use0for a positive and-1for a negative Float (dividing would give another number:(1e20 / 2**40).to_iis90949470, where1e20 >> 40was0); for a count of 0, keep the Float.
String#valid_encoding? is not in the default build (#561)
Section titled “String#valid_encoding? is not in the default build (#561)”- Before: defined by mruby-string-ext. With the default
build_config.rb, ngx_mruby 2.x builds mruby withoutMRB_UTF8_STRING, and the method returnstruefor every string, even"\xfe". A build whosebuild_config.rbdefinesMRB_UTF8_STRINGgetsfalsefor a string that is not valid UTF-8. - Now: since mruby 3.4 only mruby-encoding defines the method, and the default build leaves that gem out, so a call raises
NoMethodError(undefined method 'valid_encoding?' for String) and a handler that calls it answers 500. - Affected: scripts that call
String#valid_encoding?. - What to do: with the default
build_config.rbof 2.x, drop the call (it never returnedfalsethere), or build with mruby-encoding and check the scripts as Core gems says. A 2.x build that definedMRB_UTF8_STRINGneeds mruby-encoding to keep the check. Why the default build leaves mruby-encoding out: the gem definesMRB_UTF8_STRINGfor the whole build, soString#size,#[]and#indexcount characters instead of bytes, and a script that computes aContent-LengthfromString#sizewould get another number; the owner decided on 2026-10-04 to leave it out of the default build and keep it opt-in.
A seeded Random gives other numbers (#561)
Section titled “A seeded Random gives other numbers (#561)”- Before:
Random.new(seed)andsrand(seed)give one sequence for a seed (xoshiro). - Now: another sequence for the same seed: mruby 4.0 uses PCG instead of xoshiro.
- Affected: scripts that depend on the numbers of a seeded generator.
- What to do: do not depend on the numbers of a seeded generator across versions.
Set#inspect and Set#to_s use a new format, and Set#flatten_merge is removed (#561)
Section titled “Set#inspect and Set#to_s use a new format, and Set#flatten_merge is removed (#561)”- Before:
#<Set: {1, 2}>.Set#flatten_mergeis a public method:Set.new([1]).flatten_merge(Set.new([2, Set.new([3])]))is the Set of 1, 2 and 3. - Now:
Set[1, 2]. Everything that prints a Set with these methods changes with them: string interpolation ("#{set}"),sprintf("%s", set)andArray#inspect. mruby 4.0.0 removedSet#flatten_merge, and a call raisesNoMethodError; mruby’s lists of user-visible changes do not name it. - Affected: scripts that use the
inspectorto_sof a Set as a data format, or compare it with a fixed string, and scripts that callSet#flatten_merge. - What to do: as for
Hash#inspect: build the string yourself (set.to_a.join(",")gives the same string on both versions). In place ofs.flatten_merge(t), calls.merge(Set.new(t).flatten), which gives on both versions the Set thats.flatten_merge(t)gave on 2.x, for a Set and for an Arrayt.
Hash#default_proc= raises TypeError for an object that is not a Proc (#561)
Section titled “Hash#default_proc= raises TypeError for an object that is not a Proc (#561)”- Before: accepted.
- Now:
TypeError. - Affected: scripts that pass
Hash#default_proc=an object that is not a Proc. - What to do: pass a Proc or
nil.
yield with keyword arguments to a block with keyword parameters works (#561)
Section titled “yield with keyword arguments to a block with keyword parameters works (#561)”- Before:
ArgumentError: missing keyword. - Now: the block gets the keyword arguments.
- Affected: scripts that yield keyword arguments to a block that takes keyword parameters, for example a script that rescued the
ArgumentError. - What to do: nothing; it is a bug fix of mruby.
A return inside a block or a for body of handler code ends the code (#561)
Section titled “A return inside a block or a for body of handler code ends the code (#561)”- Before: a
returninside a block, such as[0].each do ... endor3.times { ... }, or inside the body offor, at the top level of handler code raisedLocalJumpError, and the handler answered 500 withmrb_run failed: return 500 HTTP status code to client: error: unexpected return (LocalJumpError)inerror.log. A content handler that had written output before it answered 500 as well and did not send that output. 2.7.0 sent that output with 200 and only logged the exception; 2.7.1 changed this for every exception afterNginx.rputs(entry 3 of the 2.7.1 release notes). The variable ofmruby_set_codegot an empty value. Areturnat the top level of the code, outside a block, ended the code. - Now: such a
returnends the code, as areturnat the top level does. The code after it does not run, and the response is the one that the code set before it: the status thatNginx.returnset and the output thatNginx.rputswrote. Inmruby_set_code, the value of areturnin a block becomes the variable.error.loghas no line for it. - Why it changed:
- The defect: #502: the
returnthat ends a handler early raisedLocalJumpErrorwhen it was written inside a block or aforbody, and the handler answered 500 instead of the response that the code had set. - Why the old behavior could not be kept: the error came from mruby 3.3.0. ngx_mruby runs handler code in the first frame of a fiber; mruby 3.3.0 refuses that frame as the frame that such a
returnleaves, and mruby 4.0.0 and 4.1.0-rc2 accept it (section 1.3 of the proposal for the frame of handler code). Keeping the error would have meant changing the bundled mruby back to the rule of 3.3.0, for a behavior that #502 reports as a defect. - What the documentation promised: docs/class_
and_ of 2.x says that ngx_mruby supports themethod/README.md returnstatement in handler code and that it returns from the handler, with no exception for a block.
- The defect: #502: the
- Affected: handler code with a
returninside a block or the body offorat its top level; areturninside a method or a lambda is not affected. Log alerts and scripts that relied on the 500 or on theLocalJumpErrorline are affected as well. - What to do: nothing. The two ways around it on 2.x, a
returnat the top level of the code and the code in a method or a lambda, work on both versions. - Not changed by this release: the frame in which handler code runs.
selfismain, local variables belong to one run of the code, and constants, globals, instance variables ofmainand methods defined withdefpersist in the worker (section 1.4 of the proposal).
A content handler that ends without output answers 200 with an empty body instead of 500 (#574)
Section titled “A content handler that ends without output answers 200 with an empty body instead of 500 (#574)”- Before: on 2.7.1 and 2.7.2, a content handler on the main request that ended without output (it wrote nothing, or only
""ornilwithNginx.rputs, or only set response headers) got 500 with nginx’s error page (or theerror_pageconfigured for 500) andConnection: closewhen it set no status,Nginx::HTTP_OK(withNginx.return,Nginx.send_headerorNginx.status_code=) or another status below 300 other than 201 and 204 (for exampleNginx::HTTP_ACCEPTED), also afterNginx::Async::HTTP.sub_requestresumed it (entry 13 of the 2.7.1 release notes). error.log got a line at theerrorlevel:status code is 200, but response body is empty. return NGX_HTTP_INTERNAL_SERVER_ERROR,status code is not set, and response body is empty. return NGX_HTTP_INTERNAL_SERVER_ERRORorstatus code is <N>, but response body is empty. return NGX_HTTP_INTERNAL_SERVER_ERROR. On 2.7.0 and earlier,Nginx::HTTP_OKwithout output got the same 500, and the other cases got no response at all: nginx closed an HTTP/1.0 connection without sending a byte and kept a keep-alive connection open without a response untilkeepalive_timeout. - Now: such a handler answers as nginx’s own
return 200;does: with the status it set, 200 when it set none,Content-Length: 0and an empty body. It sends noContent-Type, as ngx_mruby’s answers with output do not; nginx’sreturn 200;sends the one ofdefault_type. A HEAD request gets the same header. The header filters and body filters of the location (mruby_output_header_filter,mruby_output_body_filterand their_codeforms) run on the empty response. The empty answer discards an unread request body first, as the answer with output does since 2.7.1 (entry 12 of the 2.7.1 release notes), so the next request on a kept connection is the one that the client sent after the body. nginx keeps an otherwise reusable connection for the next request, including a HEAD response finalized by the known-length output body filter. error.log gets none of the lines above for it. - Why it changed:
- The defect: #200: a content handler that ended with
Nginx.return Nginx::HTTP_OKand no body answered 500, where nginx’s ownreturn 200;answers 200 with an empty body. HTTP allows that response: “a 200 response is expected to contain message content unless the message framing explicitly indicates that the content has zero length” (RFC 9110, section 15.3.1), whichContent-Length: 0does. 2.7.1 gave the same 500 to no status and to the other statuses below 300 that nginx does not answer by itself, because those requests had got no response at all (#566). - Why the old behavior could not be kept: with the 500, a content handler cannot answer 200 with an empty body at all; the only empty answer that it can choose is 204, which is another status for clients and caches. The v3 plan accepts the empty 200 as a behavior change of v3 (section 7, item 8 of docs/proposals/v3-plan.md); the 2.x line keeps the 500 because it puts compatibility first.
- What the documentation promised: the documentation of 2.7.1 described the old behavior: a content handler that ends without output answers 500, and an empty body takes
Nginx::HTTP_NO_CONTENT(Nginx.return of 2.7.1). Before 2.7.1, it said only thatNginx.return“Returns nginx status code to send back HTTP status to the client” (Nginx.return of 2.7.0).
- The defect: #200: a content handler that ended with
- Affected:
mruby_content_handlerandmruby_content_handler_codehandlers that can end without output, for example a handler that writes only when a condition holds, one that passes a value that can be empty orniltoNginx.rputs, one that only sets response headers, and one that ends withNginx.return Nginx::HTTP_OKand no body, and log monitoring of the lines above. Unchanged: a status below 200 without output (500 and thestatus code is <N>, but response body is emptyline, as on 2.7.1 and 2.7.2), 201, 204 and the statuses from 300 up (nginx answers them), handlers with output,Nginx.redirect, the other handlers (Nginx.return Nginx::HTTP_OKwithout output in a rewrite or access handler still answers 500 and logsstatus code is 200, but response body is empty), and subrequests (Nginx::Async::HTTP.sub_request, SSI includes andauth_request): the content handler of a subrequest that returnsNginx::HTTP_OKwithout output still sets the subrequest’s status to 500. nginx’s ownreturn 200;gives a subrequest 200 instead. Keeping the 500 makesauth_requesttreat that result as an error, instead of allowing the request as a 2xx result would. A handler that writes nothing and sets no status still ends the subrequest without a response body and without a status. - What to do: nothing for most configurations: a handler that should answer with an empty body may now return
Nginx::HTTP_OK. A script that relied on the 500 to signal that it had nothing to send must set that status itself, for exampleNginx.return Nginx::HTTP_INTERNAL_SERVER_ERRORorNginx.return Nginx::HTTP_NOT_FOUND, which nginx answers as before. Log monitoring that matchesresponse body is empty. return NGX_HTTP_INTERNAL_SERVER_ERRORfinds only the statuses below 200 of content handlers, andNginx::HTTP_OKin the other handlers and in subrequests. - Tests: port 18136 (
test/conf/conf.d/54-content-empty-body.conf,test/t/cases/content_empty_body.rb, with twoPOSTrequests whose body the handler does not read on one connection), and the cases “Nginx.return 200 dont have body” oftest/t/ngx_mruby.rband “send_header 200 without a body answers 200 with an empty body” oftest/t/cases/request_api.rb.
An output body filter that ends with an empty body sends the response instead of closing the connection (#574)
Section titled “An output body filter that ends with an empty body sends the response instead of closing the connection (#574)”- Before: when an output body filter (
mruby_output_body_filter,mruby_output_body_filter_code) ended with an empty body, because it set""withNginx::Filter#body=orNginx::Filter#output, or because the response had no body and the filter left it empty, nginx loggedzero size buf in writerat thealertlevel and closed the connection before it wrote the status line: the client received no byte. This holds on 2.7.2, 2.7.1 and earlier releases. - Now: the response is sent with its status,
Content-Length: 0and an empty body, and error.log gets noalertline for it. - Why it changed:
- The defect: the body filter passed on the empty body as a buffer of zero bytes marked as being in memory, which nginx’s writer rejects (
zero size buf in writer), so the response was never sent. nginx’s ownreturn 200;passes an empty last buffer that is not marked so (ngx_http_send_response). The 2.x line has this defect up to 2.7.2:test/t/cases/filter_connection.rbof 2.7.1 records it as the behavior of 2.x (“an empty String closes the connection without a response”). 2.7.3 fixes it on the 2.x line in the same way (entry 8 of the 2.7.3 release notes). - Why the old behavior could not be kept: a response that is never sent leaves the client without an answer. The empty 200 of the entry above also passes through the body filter of its location, so without this change such a location would send no response at all instead of the empty 200.
- What the documentation promised: Nginx::
Filter says that the response is sent with exactly the body that the filter sets, and that#body= of 2.7.1 Content-Lengthis its length, with no exception for an empty String.
- The defect: the body filter passed on the empty body as a buffer of zero bytes marked as being in memory, which nginx’s writer rejects (
- Affected: locations with an output body filter that can end with an empty body, including a location whose content handler ends without output (the entry above), and log monitoring of the
zero size buf in writerline, which these responses no longer log. - What to do: nothing.
- Tests: port 18112 (
test/t/cases/filter_connection.rb, “an empty String sends the status with Content-Length: 0”) and the locations with a body filter on port 18136 (test/t/cases/content_empty_body.rb).
The accessors of Nginx::Var become methods of Nginx::Var at their first use in a worker (#610)
Section titled “The accessors of Nginx::Var become methods of Nginx::Var at their first use in a worker (#610)”- Before: every
v.NAMEandv.NAME = valueon anNginx::Varwent throughNginx::Var#method_missing.Nginx::Varhad three methods of its own,method_missing,exist?andset:v.respond_to?(:request_method)returnedfalse, andNginx::Var.instance_methods(false)listed only those three. When a script defined a method onObjectorKernelwhose name was also the name of a variable, for example with adefat the top level of handler code,v.NAMEcalled that method instead of reading the variable. - Now: the first
v.NAMEorv.NAME = valueof a name in a worker process also definesNAMEorNAME=as a method ofNginx::Var, and the later accesses of the name in that worker call the method. The method reads and writes the variable asmethod_missingdoes: the values,nilfor a name that is not a variable, the exceptions and the lines oferror.logare the same. A worker defines a getter and a setter for each declared variable that scripts use (the variables of nginx and its modules, and the ones thatsetdeclares), and a getter for the first 16 names of prefix variables that scripts use, such asarg_qorhttp_x_request_id. A name gets a method only when it is made ofatoz,0to9and_, with=at the end for a setter;v.Request_Methodkeeps reading$request_methodthroughmethod_missing. A name that is not a variable, a setter of a prefix variable, an instance of a subclass ofNginx::Var, a frozenNginx::Var, and a name thatNginx::Varor one of its ancestors already has as a method get no method. After the first access,v.respond_to?(:NAME),v.methods,Nginx::Var.instance_methods(false)andNginx::Var.method_defined?(:NAME)show the method. What they show depends on the requests that the worker has served, so two workers can answer differently. Once the method exists, a method of the same name that a script defines later onObjectorKernelno longer hides the variable fromv.NAME. - Why it changed:
- The reason: with mruby 4.0.0, the lookup of a method name that no class defines compares the name with every method of
Nginx::Var,Object,KernelandBasicObject, more than 110 entries, and mruby does not cache a name that it did not find. Eachv.NAMEpaid that search beforemethod_missingran. In the callgrind comparison of #561, the search made 74% of the difference of thevarscenario and 59% of that of theauthscenario against mruby 3.3.0 (section 1.1 of the proposal). A method of the name is found in mruby’s method cache instead. - Why the old behavior could not be kept: mruby’s method cache answers only for a method that the lookup found, so a change that lets
v.NAMEskip the search has to define a method, and introspection shows it. The other ways of the proposal leave the scripts as they are written today on the slow path, or wait for a release of mruby (section 2 of the proposal). The owner accepted the change to introspection as a behavior change of 3.0.0 on 2026-10-15, and confirmed it on 2026-10-19 (the status of the proposal). - What the documentation promised: the Nginx::
Var class of 2.7.1 says thatNginx::Var#method_missingis called whenNginx::Var#VARNAMEorNginx::Var#VARNAME=is evaluated. It said nothing aboutrespond_to?or the methods ofNginx::Var.
- The reason: with mruby 4.0.0, the lookup of a method name that no class defines compares the name with every method of
- Affected: scripts that call
respond_to?,methods,instance_methodsormethod_defined?onNginx::Varor its instances, for example to tell whether a name is a variable, scripts that define a method onObjectorKernelwith the name of a variable that they also read withv.NAME, and scripts that wrapNginx::Var#method_missing, for example with a module prepended toNginx::Varwhosemethod_missingcallssuper: the wrapper runs only for the first access of a name that gets a method. - What to do: use
v.exist?(name)to tell whether a variable exists. Give the methods of your scripts names that are not names of nginx variables. - Tests: port 18159 (
test/conf/conf.d/68-var-accessor.conf,test/t/cases/var_method_lookup.rb).
Nginx::Connection, Nginx::Server and Nginx::Request read their variables without calling Nginx::Var (#610)
Section titled “Nginx::Connection, Nginx::Server and Nginx::Request read their variables without calling Nginx::Var (#610)”- Before:
Nginx::Connection#remote_ip,#remote_port,#local_ipand#local_port,Nginx::Server#document_root,#realpath_rootand#path, andNginx::Request#hostname,#authority,#filename,#userand#get_bodycalled the accessor of their variable (remote_addr,remote_port,server_addr,server_port,document_root,realpath_root,host,http_host,request_filename,remote_userandrequest_body) on anNginx::Varthat the object created and kept in its instance variable@iv_var. A script that defined such a method onNginx::Var, defined amethod_missingof its own there, or put another object in@iv_var, changed what these methods returned. - Now: these methods read the variable from nginx in C. They return the value that nginx has for the variable, whatever methods a script defines on
Nginx::Var, and they neither create anNginx::Varnor set@iv_var.Nginx::Request#varstill creates theNginx::Varof the object and keeps it in@iv_var. Outside a request they raise the sameRuntimeErroras before. - Why it changed:
- The reason: the names of these variables are fixed, and “Design principles” in
AGENTS.mdasks that nothing fixed is looked up or allocated per request when it can be prepared once at initialization. The Ruby call looked the method up onNginx::Varon each call, which takes the search of the entry above, and each object created anNginx::Varand looked up its class. The names and their hash keys are now prepared once (candidate (d) of the proposal). - Why the old behavior could not be kept: the Ruby call on the object in
@iv_varis what let a script change the values. Reading the variable without that call removes both the cost and that effect. - What the documentation promised: the Nginx::
Connection class of 2.7.1 says thatremote_ip,remote_port,local_ipandlocal_portare the same as the nginx variables$remote_addr,$remote_port,$server_addrand$server_port, and Nginx::Server says the same of#realpath_ root $realpath_root. That is what they return now in every case.
- The reason: the names of these variables are fixed, and “Design principles” in
- Affected: scripts that change what these methods return by defining methods on
Nginx::Var, amethod_missingof their own on it, or another object in@iv_var, and scripts that read@iv_varof these objects without callingNginx::Request#varfirst. - What to do: to return another value, define the method on
Nginx::Connection,Nginx::ServerorNginx::Requestitself, or call a method of your own. Read variables withNginx::Var(Nginx::Request#var,Nginx.varorNginx::Var.new) instead of@iv_var. - Tests: port 18159 (
test/t/cases/var_method_lookup.rb).
Dir comes from mruby’s core gem, and a closed Dir raises IOError instead of RuntimeError (#559)
Section titled “Dir comes from mruby’s core gem, and a closed Dir raises IOError instead of RuntimeError (#559)”- Before:
Dircomes from iij/mruby-dir. Reading, iterating or closing aDirthat is closed raisesRuntimeError(closed directory), and so doesDir.openwith a block when the block closes theDir.Dir#eachandDir.foreachwithout a block raiseNoMethodError. - Now:
Dircomes from mruby-dir, a core gem of mruby 4 that started from iij/mruby-dir and has every method of it. Reading, iterating or closing aDirthat is closed raisesIOError(closed directory).Dir.openwith a block returns the value of the block also when the block closes theDir.Dir#eachandDir.foreachwithout a block return anEnumerator.Dir.foreachwith a block closes theDirthat it opened (see “Fixes”), andDirhas methods that iij/mruby-dir does not have (see “New features”). - Why it changed:
- The reason: the v3 plan replaces the third-party gems iij/mruby-env, iij/mruby-process and iij/mruby-dir with core gems of mruby (
docs/proposals/v3-plan.md, section 4, Pillar A). mruby 4.0.0 had a core gem only forDir; 4.1 also has mruby-env and mruby-process, which replace the other two gems of iij (#766). - Why the old behavior could not be kept: the
RuntimeErrorcomes from iij/mruby-dir, which raises it for a closed directory unless it is compiled withENABLE_IO, and the default build does not define it. Keeping theRuntimeErrorwould have meant keeping iij/mruby-dir, which has had no commit since 2018-09-14 and leaves theDirthatDir.foreachopens open until the GC frees it. - What the documentation promised: docs/class_
and_ of 2.x lists themethod/README.md Dirclass among the classes of the default build and links it to iij/mruby-dir, whose README lists the methods and says nothing about the exception for a closedDir.
- The reason: the v3 plan replaces the third-party gems iij/mruby-env, iij/mruby-process and iij/mruby-dir with core gems of mruby (
- Affected: scripts that rescue
RuntimeErroraround the methods of aDirthat can be closed, or aroundDir.openwith a block that closes theDir. When therescue RuntimeErrorno longer catches the exception, the handler answers 500 (mrb_run failed: ... error: #<IOError: closed directory>). - What to do: rescue
IOError. A script that runs on both versions rescuesIOErrorandRuntimeError, orStandardError.
ENV comes from mruby’s core gem: ENV.to_hash is gone, and ENV is Enumerable (#766)
Section titled “ENV comes from mruby’s core gem: ENV.to_hash is gone, and ENV is Enumerable (#766)”- Before:
ENVcomes from iij/mruby-env. It has[],[]=,store,delete,fetch,has_key?(andkey?,include?,member?),keys,values,size,to_a,to_hash,inspect,to_sandclear.ENV.each,ENV.to_h,ENV.select,ENV.empty?andENV.lengthraiseNoMethodError. Setting a variable whose name contains=raisesRuntimeError(can't change environment variable), andENV.freezereturnsENV. - Now:
ENVcomes from mruby-env, a core gem of mruby 4.1. It has the methods above exceptto_hash, which raisesNoMethodError;ENV.to_hreturns the variables as a Hash.ENVincludesEnumerableand haseach(each_pair),each_key,each_value,select(filter),reject,slice,empty?,length,key,has_value?(value?),assoc,rassoc,replaceandupdate(merge!). A name that contains=or a NUL byte, and a value that contains a NUL byte, raiseArgumentError.ENV.freezeraisesTypeError. TheKeyErrorofENV.fetchquotes the name (key not found: "NAME"). - Why it changed:
- The reason: the v3 plan replaces iij/mruby-env, iij/mruby-process and iij/mruby-dir with core gems of mruby (
docs/proposals/v3-plan.md, section 4, Pillar A, and step 3 of section 6). iij/mruby-env has had no commit since 2018-09-03, and mruby 4.1 has a core gem of the same name, mruby-env, that definesENV. - Why the old behavior could not be kept:
to_hashand theRuntimeErrorcome from iij/mruby-env. Keeping them would have meant keeping that gem in place of mruby’s own gem of the same name. - What the documentation promised: docs/class_
and_ of 2.x listsmethod/README.md ENVamong the classes of the default build and links it to iij/mruby-env, whose README liststo_hashamong its methods and says nothing about the exceptions.
- The reason: the v3 plan replaces iij/mruby-env, iij/mruby-process and iij/mruby-dir with core gems of mruby (
- Affected: scripts that call
ENV.to_hash, or that rescueRuntimeErroraround setting a variable with=in its name. nginx removes the environment variables of its workers exceptTZand the ones thatenvdirectives name, so the variables that a handler sees are those. - What to do: call
ENV.to_hin place ofENV.to_hash. A script for both versions usesENV.keys.each_with_object({}) { |k, h| h[k] = ENV[k] }, or reads the variables it needs withENV[name].
Process comes from mruby’s core gem: Process.fork, Kernel#fork and Kernel#system are gone (#766)
Section titled “Process comes from mruby’s core gem: Process.fork, Kernel#fork and Kernel#system are gone (#766)”- Before:
Processcomes from iij/mruby-process, which also definesKernel#forkandKernel#system. A handler can start a child process withforkorProcess.forkand run a shell command withsystem.Process::Status#to_intreturns the raw status, andProcess::Status.new(pid, status)makes a status, for example to set$?. - Now:
Processcomes from mruby-process, a core gem of mruby 4.1. It hasProcess.pid,.ppid,.kill,.waitpid,.waitpid2and$$as before.$$is set once, when nginx reads the configuration, so in a worker under a master process it is the pid of the master, as with 2.x;Process.pidis the pid of the worker.Process::Statushas the instance methods of 2.x exceptto_int, and noProcess::Status.new: a status comes only fromProcess.waitpidand its variants, or fromIO.popenthrough$?.Process.fork,Kernel#fork,Kernel#system,Process::Status#to_intandProcess::Status.neware gone: a call raisesNoMethodError, and the handler answers 500.Process::Status#to_sdescribes the status as CRuby does (pid 1234 exit 0) instead of returning the raw status as digits,Process::Status#inspectfollows it (#<Process::Status: pid 1234 exit 0>, where 2.x printed#<Process::Status: pid=1234,exited(0)>), andProcess::Status#success?returnsnilinstead offalsefor a process that did not exit.Process::WNOHANGandProcess::WUNTRACEDkeep the values 1 and 2. The new methods are under “New features”. mruby-process depends on the core gem mruby-signal, so scripts also getSignal(Signal.listandSignal.signame; there is noSignal.trap). - Why it changed:
- The reason: the v3 plan replaces iij/mruby-process with mruby’s core gem (see the entry of
ENVabove). iij/mruby-process has had no commit since 2019-12-25. - Why the old behavior could not be kept:
forkandsystemcome from iij/mruby-process, and mruby-process of mruby 4.1.0-rc2 does not define them. Keeping them would have meant keeping that gem in place of mruby’s own gem of the same name. Aforkin a worker copies the worker, its connections included, andsystemwaits for the command, so neither fits a handler. - What the documentation promised: docs/class_
and_ of 2.x listsmethod/README.md Processamong the classes of the default build and links it to iij/mruby-process, whose README listsfork,exit,exit!,sleepandsystemunderKernel.
- The reason: the v3 plan replaces iij/mruby-process with mruby’s core gem (see the entry of
- Affected: scripts that call
fork,Process.fork,system,Process::Status#to_intorProcess::Status.new, and log parsers that readProcess::Status#to_sor#inspect. - What to do: start other processes outside nginx, for example from a service that the handler reaches over the network, or run a command with
IO.popenof mruby-io, which waits in the worker assystemdid. CallProcess::Status#to_iin place ofto_int. The core gem has no replacement forProcess::Status.new: keep the pid and the status in variables of your own. UseProcess.pidfor the pid of the worker.
exit in a handler raises SystemExit instead of ending the worker process (#766)
Section titled “exit in a handler raises SystemExit instead of ending the worker process (#766)”- Before: iij/mruby-process defines
Kernel#exitandKernel#exit!, and its definitions replace those of the core gem mruby-exit, because the build initializes iij/mruby-process after the core gems.exitcallsexit(3)of the C library: in a handler, it ends the nginx worker process, and the requests that the worker was serving end without a response.exit!calls_exit(2). - Now:
exitcomes from mruby-exit and raisesSystemExit. In a handler, the exception ends the handler like any other exception: the handler answers 500 anderror.loghas themrb_run failedline; the worker keeps running.rescue => edoes not catchSystemExit, which is not aStandardError.exit!comes from mruby-exit as well and callsexit(3), which ends the process and runs theatexithandlers; without an argument it exits with status 0, where theexit!of 2.x exited with 1 through_exit(2). Outside handlers, inmruby_init,mruby_init_code,mruby_init_worker,mruby_exit_workerand the stream code,exitraisesSystemExitas well, and ngx_mruby treats it as an exception of that code: inmruby_initandmruby_init_code, for example, nginx stops reading the configuration with an error, where 2.x ended the nginx that read it. - Why it changed:
- The reason: the definitions of iij/mruby-process left the build with it (see the entry of
Processabove). With the build ofnextbefore this change,mruby -e 'exit 3'ended with status 3 without raisingSystemExit, and with this change the same code raisesSystemExit. 2.x declares iij/mruby-process afterfull-core.gemboxin the same way, and its mruby sorts the gems by the same rule. - Why the old behavior could not be kept: the old
exitcame only from iij/mruby-process. A worker that ends drops the requests of every client that it serves, and the master starts another worker. - What the documentation promised: the documentation of 2.x did not describe
exitin a handler. The README of iij/mruby-process listsexitandexit!underKernel.
- The reason: the definitions of iij/mruby-process left the build with it (see the entry of
- Affected: scripts that call
exitin a handler, whether to stop the worker or to end the handler, scripts that callexitin the code that nginx runs outside requests, and scripts that callexit!without an argument. - What to do: remove
exitfrom handlers. To answer with a status, callNginx.returnwith it and let the code run to its end. To stop nginx, send nginx’s signals to the master process.
sleep without an argument raises ArgumentError (#766)
Section titled “sleep without an argument raises ArgumentError (#766)”- Before: iij/mruby-process defines
Kernel#sleep, which replaces the one of the core gem mruby-sleep for the same reason asexit(see the entry above). It takes no argument or one:sleepwithout an argument waits until the process gets a signal, and in a handler it stops the worker for good. - Now:
sleepcomes from mruby-sleep and takes exactly one argument, an Integer or a Float of seconds.sleepwithout an argument raisesArgumentError, and the handler answers 500. A negative number raisesArgumentError(time interval must not be negative), where 2.x raised the error ofselect(2)(Errno::EINVAL).usleepcame from mruby-sleep before as well and is unchanged. - Why it changed:
- The reason: the definition of iij/mruby-process left the build with it (see the entry of
Processabove). - Why the old behavior could not be kept: the old
sleepcame only from iij/mruby-process. - What the documentation promised: the documentation of 2.x did not describe
sleepwithout an argument.
- The reason: the definition of iij/mruby-process left the build with it (see the entry of
- Affected: scripts that call
sleepwithout an argument, or rescueErrno::EINVALaroundsleepwith a negative number. Asleepwith an argument still waits in the worker;Nginx::Async.sleepwaits without blocking it. - What to do: give
sleepthe seconds to wait, or useNginx::Async.sleepwith milliseconds in a handler.
The default build leaves out Vedis and Cache (mruby-vedis and mruby-localmemcache) (#766)
Section titled “The default build leaves out Vedis and Cache (mruby-vedis and mruby-localmemcache) (#766)”- Before: the default build has matsumotory/mruby-vedis, which defines
Vedis, an embedded key-value store, and matsumotory/mruby-localmemcache, which definesCache, a key-value store in shared memory on the localmemcache library. - Now: the default build has neither gem. A script that uses
VedisorCacheraisesNameError, and its handler answers 500 (mrb_run failed: ... error: #<NameError: uninitialized constant Vedis>). Both lines stay inbuild_config.rbas comments. - Why it changed:
- The reason: the v3 plan drops both gems from the default list (
docs/proposals/v3-plan.md, section 4, Pillar A). The build of mruby-vedis clones symisc/vedis at the head of its default branch, whichbuild_config.rb.lockcannot pin and which has had no commit since 2021-11-25. mruby-localmemcache carries a copy of localmemcache, whose repository sck/localmemcache has had no commit since 2013-05-21. - Why the old behavior could not be kept: keeping the gems would keep, in every default build, a library that no one updates and, for vedis, a clone that the lock does not pin. AGENTS.md (“Other repositories”) allows removing a gem of the owner when the library under it is no longer maintained.
- What the documentation promised: docs/class_
and_ of 2.x listsmethod/README.md CacheandVedisamong the classes of the default build.
- The reason: the v3 plan drops both gems from the default list (
- Affected: scripts that use
VedisorCache. - What to do: keep the data in Redis (
Redis, in the default build) or in a store of your own. To keep using a gem, uncomment its line inbuild_config.rb, removemruby/buildand build again; the first build clones the head of the gem’s branch and adds its entry tobuild_config.rb.lock. The test suite of this release does not run with these gems.
Digest and SecureRandom come from gems of ngx_mruby that need OpenSSL 3.0 or later (#771)
Section titled “Digest and SecureRandom come from gems of ngx_mruby that need OpenSSL 3.0 or later (#771)”- Before:
Digestcomes from iij/mruby-digest andSecureRandomfrom monochromegane/mruby-secure-random. iij/mruby-digest builds with OpenSSL 1.0.2 and later, and on macOS with CommonCrypto instead of OpenSSL.dupandcloneof aDigest::SHA256(or another class ofDigest) return an object that has taken no data. With OpenSSL 1.1 and later,Digest::HMAC#digestand#hexdigestend the HMAC: a second call, or a call afterupdatethat follows the first, does not return the HMAC of the data. With OpenSSL 3.0.0 to 3.0.6, whose default provider has no RIPEMD160,Digest::RMD160does not return the RIPEMD160 hash.SecureRandomopens and reads/dev/urandomon every call.SecureRandom.urlsafe_base64(n)ignoresnand encodes 16 random bytes.SecureRandom.random_byteswith a negative number raisesNameError: the gem rescues theArgumentErrorofIO#readand raisesFile::NoFileError, which mruby-io does not define. - Now:
Digestcomes frommrbgems/digestof this repository, which computes the hashes with the EVP API of OpenSSL 3 and HMAC withEVP_MAC, andSecureRandomfrommrbgems/secure-random, which takes the bytes fromRAND_bytesof OpenSSL. The classes, methods, arguments and return values are those of the two gems (Digest and SecureRandom in the documentation of the classes), with these differences:dupandcloneof a digest copy the data that it has taken;Digest::HMAC#digestand#hexdigestleave the HMAC as it was, so they can be called again andupdatecan follow;Digest::RMD160.new(andnewof any class ofDigestwhose algorithm the OpenSSL of the process does not provide, such as MD5 under the FIPS provider) raisesNotImplementedError;SecureRandomopens no file;SecureRandom.urlsafe_base64(n)encodesnbytes; andSecureRandom.random_byteswith a negative number raisesArgumentError. The build of the bundled mruby stops on an OpenSSL older than 3.0 with#error, on LibreSSL and BoringSSL, which have noEVP_MAC, and on macOS without the headers and thelibcryptoof an OpenSSL 3. The two gems have the gem names of the gems that they replace, mruby-digest and mruby-secure-random, so a third-party gem that depends on one of these names gets the gem of this repository. - Why it changed:
- The reason: the v3 plan replaces mruby-secure-random with a small gem on
RAND_bytesorgetrandomand reimplements mruby-digest on the EVP API of OpenSSL 3 (docs/proposals/v3-plan.md, section 4, Pillar A). The list of mruby gems has no maintained replacement: Asmod4n/mruby-sysrandom has another API, and nothing replaces mruby-digest. iij/mruby-digest computes HMAC withHMAC_CTX, which OpenSSL 3 deprecates. Gems in this repository are checked by the test suite, CI and theperfjob of ngx_mruby. The v3 plan sets OpenSSL 3.5 as the baseline and drops 1.1.1 and 3.0 (item 3 of section 7). - Why the old behavior could not be kept: the differences of
dup,Digest::HMAC#digestandurlsafe_base64(n)are defects of the old gems that a script cannot rely on, and keeping them would mean writing them again on purpose.EVP_MAC, which OpenSSL 3 provides in place ofHMAC_CTX, does not exist in OpenSSL 1.1.1, LibreSSL or BoringSSL. - What the documentation promised: docs/class_
and_ of 2.x listsmethod/README.md DigestandSecureRandomamong the classes of the default build and links them to the two gems. The README of iij/mruby-digest says that its classes are compatible with those of CRuby, wheredupof a digest keeps its data and an HMAC object returns its digest more than once. The README of mruby-secure-random showsurlsafe_base64withoutnand says nothing aboutn.
- The reason: the v3 plan replaces mruby-secure-random with a small gem on
- Affected: builds with OpenSSL 1.1.1 or older, LibreSSL or BoringSSL, also with
--with-openssl-src, and builds on macOS that took CommonCrypto; scripts that callduporcloneof a digest,digestorhexdigestof aDigest::HMACmore than once,Digest::RMD160orurlsafe_base64(n), or rescueNameErroraroundrandom_bytes; and abuild_config.rbof your own that adds iij/mruby-digest or monochromegane/mruby-secure-random next to the default gems, which defines the same gem twice. - What to do: build with OpenSSL 3.0 or later (3.5 is the baseline of v3); on macOS, install OpenSSL 3, for example with Homebrew, whose
/opt/homebrew/opt/openssland/usr/local/opt/opensslconfigurefinds; give the include and lib directories of an OpenSSL 3 in another place inNGX_MRUBY_CFLAGSandNGX_MRUBY_LDFLAGS. A script that relied onurlsafe_base64(n)returning 22 characters callsurlsafe_base64withoutn. A script that relied ondupstarting empty callsDigest::SHA256.new(or the class it uses) instead. Remove a line of iij/mruby-digest or monochromegane/mruby-secure-random from abuild_config.rbof your own.
nginx 1.30 (stable) and 1.31 (mainline) are the oldest supported versions (#789)
Section titled “nginx 1.30 (stable) and 1.31 (mainline) are the oldest supported versions (#789)”- Before: the CI of 2.7.5 builds and tests nginx 1.31.8, 1.30.6, 1.28.3 and 1.26.3, and the source of 2.x keeps
nginx_versionbranches for nginx versions down to 0.8.11. With nginx 1.24.0, 2.x builds only without the stream module: with the default options ofbuild.sh(--with-stream) the build stops while it compilessrc/stream/ngx_stream_mruby_core.c, withunknown type name 'ngx_stream_listen_opt_t'(measured on 2026-11-11 with 2.7.5 and withmasterat10c4cd927). - Now: this release supports nginx 1.30 (stable) and 1.31 (mainline), which its CI builds and tests (1.30.6 and 1.31.8). The oldest supported versions move up every April, when nginx starts a new stable line. The
nginx_versionbranches ofsrc/for nginx older than 1.25.5 are removed. Neither./configurenorbuild.shchecks the version of nginx: on 2026-11-11,build.sh, with and without--with-stream, completed with nginx 1.28.3 and 1.26.3, which CI does not test, and stopped with nginx 1.24.0 while it compiledsrc/http/ngx_http_mruby_server.c, with'ngx_http_listen_opt_t' has no member named 'type'. - Why it changed:
- The reason: item 2 of section 7 of the v3 plan sets nginx 1.30 stable and 1.31 mainline as the oldest versions that v3 supports, raised every April, and its Pillar A row removes the branches for nginx older than 1.25.5 (
docs/proposals/v3-plan.md). nginx.org lists 1.28.3 and 1.26.3 as legacy versions, and the fixes of nginx after 1.30.0 went only to 1.30.x and 1.31.x (section 3.1 of the plan). - Why the old behavior could not be kept: each supported nginx line adds four cells to the build matrix of the nightly run and of the check before a tag, for lines that nginx no longer fixes. The removed branches served nginx versions that CI had not built for years, so no test checked them.
- What the documentation promised: the README of 2.7.5 says that ngx_mruby supports the nginx mainline and stable lines, without versions, and says that v3 will support 1.30 and 1.31 as the oldest versions.
- The reason: item 2 of section 7 of the v3 plan sets nginx 1.30 stable and 1.31 mainline as the oldest versions that v3 supports, raised every April, and its Pillar A row removes the branches for nginx older than 1.25.5 (
- Affected: builds with an nginx older than 1.30: builds with nginx 1.28 or 1.26, which 2.x builds and tests, and builds with nginx 1.24, such as the package of Ubuntu 24.04, which 2.x builds only without the stream module.
- What to do: build with nginx 1.30 or 1.31. To keep nginx 1.28 or 1.26, stay on 2.x (the branch
v2.xor the latestv2.*tag), which is supported for twelve months after v3.0.0 (SECURITY.md). With nginx 1.24, 2.x builds only without--with-stream.
C extensions: an object of a class not declared MRB_TT_DATA cannot wrap C data (#561)
Section titled “C extensions: an object of a class not declared MRB_TT_DATA cannot wrap C data (#561)”- Before: mruby 3.x did not check a class whose instance type was not set: a gem that wraps a C struct with
Data_Wrap_Structormrb_data_object_allocin an object of its own class got the object. - Now: mruby 4.0 raises
TypeError: allocation failure of <class>at the allocation, unless the class is declared withMRB_SET_INSTANCE_TT(klass, MRB_TT_DATA). - Affected: mrbgems and C extensions that wrap C data in a class without that declaration. matsumotory/mruby-uname at its commits before matsumotory/mruby-uname#1 is one: every method of
UnameraisesTypeError: allocation failure of Uname, and a handler that calls one answers 500 (the test suite of ngx_mruby saw it,test/t/cases/gem_uname.rb). - What to do: declare the class with
MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA). The default build pins matsumotory/mruby-uname to a commit that does this (see “Build and test changes”); abuild_config.rbof your own that takes mruby-uname needs that commit or a later one.
C extensions: mruby checks the argument count of a C method against its spec (#561)
Section titled “C extensions: mruby checks the argument count of a C method against its spec (#561)”- Before: mruby 3.3 checked the argument count of a C method against the argument spec it was defined with (
MRB_ARGS_REQ(2)and so on) only when the spec wasMRB_ARGS_NONE(). For other specs, onlymrb_get_argschecked the arguments, against what it reads. - Now: mruby 4.0 checks it for every C method before the call: a call with fewer arguments than the spec requires, or, unless the spec has a rest (
MRB_ARGS_REST(),MRB_ARGS_ANY()), more than it allows, raisesArgumentError, whatevermrb_get_argswould accept. A non-empty keyword hash counts as one argument when the spec takes no keywords. A method defined withMRB_ARGS_REQ(1)that reads"o|o"raisesArgumentError: wrong number of arguments (given 2, expected 1)when called with two arguments, and one defined withMRB_ARGS_REQ(2)that reads"S"raises(given 1, expected 2)when called with one; with mruby 3.3 both calls worked. - Affected: C methods of mrbgems and C extensions whose spec differs from what their
mrb_get_argsreads, in either direction. The C methods of ngx_mruby itself are not affected: for each of the 110 definitions insrc/, the spec accepts every argument count that itsmrb_get_argsaccepts. - What to do: define the method with the spec that its
mrb_get_argsreads (for"o|o",MRB_ARGS_ARG(1, 1)).
C extensions: renamed headers and functions, and mrb_open() on failure (#561)
Section titled “C extensions: renamed headers and functions, and mrb_open() on failure (#561)”- Before:
mruby/ext/io.h,mrb_alloca(),mrb_open_allocf(f, ud)andmrb_open_core(f, ud), which take an allocator of the typemrb_allocf(by defaultmrb_default_allocf(), which a program could redefine), andmrb_open()returnsNULLwhen a gem initializer fails. - Now:
mruby/io.h(there is nomruby/ext/io.h),mrb_temp_alloc()(mruby.hkeepsmrb_alloca()as a macro for it, “for compatibility”), and nomrb_open_allocf(),mrb_allocformrb_default_allocf():mrb_open_core()takes no arguments, and mruby allocates its memory withmrb_basic_alloc_func(void *ptr, size_t size), which a program can define to replace mruby’s allocator (doc/guides/memory.mdof mruby).mrb_open()returns the state withmrb->excset, instead ofNULL, when a gem initializer fails. - Affected: C sources of mrbgems and of programs that embed mruby that include
mruby/ext/io.h, callmrb_open_allocf()or callmrb_open_core()with arguments (their build stops), that define their ownmrb_default_allocf()(mruby no longer calls it), or that test the result ofmrb_open()only forNULL. Calls ofmrb_alloca()still compile. - What to do: include
mruby/io.h, callmrb_temp_alloc(), callmrb_open()instead ofmrb_open_allocf(f, ud)andmrb_open_core()without arguments, definemrb_basic_alloc_func()instead ofmrb_default_allocf()where a program replaces the allocator, and test the result ofmrb_open()withMRB_OPEN_FAILURE()(mruby.h), which is true forNULLand for a state withexcset.
C extensions: sources that include mruby.h need the generated headers (#561)
Section titled “C extensions: sources that include mruby.h need the generated headers (#561)”- Before:
mruby.hdid not includemruby/presym.h, so a source that did not useMRB_SYM()compiled withmruby/includealone; presym could also be turned off (MRB_NO_PRESYM). ngx_mruby 2.x compiled its own sources this way: itsconfig.inputs onlymruby/srcandmruby/includeon the include path. - Now:
mruby.hincludesmruby/presym.h, which includes the generatedmruby/presym/id.h(mruby/mruby#6733), andMRB_NO_PRESYMis gone, so every source that includesmruby.hneedsbuild/host/include. Compiled withmruby/includealone, such a source stops withfatal error: mruby/presym/id.h: No such file or directory. - Affected: C sources compiled outside the mruby build that include
mruby.h, among them the sources of ngx_mruby in a build whose./configure --with-mruby-incdirgives a list of directories without that directory. - What to do: add the
includedirectory of the mruby build (mruby/build/host/include) to the include path. The build of ngx_mruby does this for its own sources: the default list of--with-mruby-incdiris<mruby_root>/src <mruby_root>/include <mruby_root>/build/host/include(#559). A list that you give with--with-mruby-incdirneeds the directory too, because the sources of ngx_mruby includemruby.handmruby/presym.h(#572, 3-B. Using Makefile).
The default build leaves out the auto-ssl mrbgem and the classes that came with it (#556)
Section titled “The default build leaves out the auto-ssl mrbgem and the classes that came with it (#556)”- Before: the default
build_config.rbof 2.x builds the bundled auto-ssl mrbgem (mrbgems/auto-ssl, theNginx::SSL::ACMEclasses) and the gems that it depends on: pyama86/mruby-acme-client, pyama86/mruby-polarssl, matsumotory/mruby-httprequest, matsumotory/mruby-simplehttp, mattn/mruby-http, mattn/mruby-base64, takahashim/mruby-forwardable and iij/mruby-tempfile. Scripts can use what these gems define:Nginx::SSL::ACME::ClientandNginx::SSL::ACME::Dehydrated; the classes and modulesAcme,CustomHttpRequest,OpenSSL,PolarSSL,HttpRequest,SimpleHttp,HTTP,Base64,Forwardable,FORWARDABLE,TempfileandTempfilePath; andDir.tmpdirandDir.mktmpdir. - Now: the default build has none of them. The constants are not defined,
Dir.tmpdirandDir.mktmpdirraiseNoMethodError, and a handler that uses one of them answers 500 (mrb_run failed: ... error: #<NameError: uninitialized constant Base64>). TheDirclass itself stays. This release has no auto-ssl mrbgem at all (see the next entry). - Why it changed:
- The reason: decision 6 of the v3 plan (
docs/proposals/v3-plan.md, section 7) removes auto-ssl from the default build of v3, to be replaced by nginx-acme and by examples that look certificates up in a store. Its ACME client,Nginx::SSL::ACME::Client, speaks ACMEv1, which Let’s Encrypt no longer serves (sections 2.2 and 3.4 of the plan). - Why the old behavior could not be kept: the gem cannot get a certificate from Let’s Encrypt, and it brought into every default build eight third-party gems that no other gem of the default build needs, pyama86/mruby-polarssl under the GPL among them. With mruby 4 the default build would also stop, because pyama86/mruby-polarssl includes
mruby/ext/io.h(see the next entry). - What the documentation promised: docs/class_
and_ of 2.x calls auto-ssl an optional bundled mrbgem in an early phase of development, without saying whether the default build has it. Its example ofmethod/README.md mruby_set_codeunder Nginx::Var Class callsBase64.encode, which the default build had only through auto-ssl.
- The reason: decision 6 of the v3 plan (
- Affected: scripts that use one of the constants above,
Dir.tmpdirorDir.mktmpdirinside nginx. - What to do: use
[s].pack('m0')in place ofBase64.encode(s)ands.unpack1('m')in place ofBase64.decode(s), both from the core gem mruby-pack,ENV['TMPDIR'] || '/tmp'in place ofDir.tmpdir, andDir.mkdir(path, 0700)under a name of your own in place ofDir.mktmpdir, as The auto-ssl mrbgem and the classes that came with it shows. For the other constants, add the gem that defines them with aconf.gemline in abuild_config.rbof your own; the gems that depend on pyama86/mruby-polarssl do not build with mruby 4. A server that needsNginx::SSL::ACMEkeeps a 2.x build (see the next entry).
The auto-ssl mrbgem and NGX_MRUBY_AUTO_SSL are removed (#640)
Section titled “The auto-ssl mrbgem and NGX_MRUBY_AUTO_SSL are removed (#640)”- Before: ngx_mruby 2.x bundles the auto-ssl mrbgem (
mrbgems/auto-ssl) and takes it in the default build. It definesNginx::SSL::ACME::Client, a client of the ACME protocol, andNginx::SSL::ACME::Dehydrated, helpers for the dehydrated ACME client;test/conf/auto-ssl/has example configurations for both. - Now: this release has no
mrbgems/auto-ssland notest/conf/auto-ssl/, andbuild_config.rbno longer readsNGX_MRUBY_AUTO_SSL, so no build of this release hasNginx::SSL::ACME. A build withNGX_MRUBY_AUTO_SSL=1in its environment builds the default gems as without it. A script that usesNginx::SSL::ACMEraisesNameError, and its handler answers 500 with amrb_run failedline inerror.log. - Why it changed:
- The reason: decision 6 of the v3 plan (
docs/proposals/v3-plan.md, section 7) replaces auto-ssl with nginx-acme and with examples that look certificates up in a store, and the gem cannot work with the bundled mruby. It needs pyama86/mruby-polarssl for TLS, a gem that ngx_mruby does not maintain and that has had no commit since 2017-03-03. That gem includesmruby/ext/io.h, which mruby 4.0 renamed tomruby/io.h, so the mruby build with auto-ssl stops withfatal error: mruby/ext/io.h: No such file or directory(#561). Its ACME client, pyama86/mruby-acme-client, speaks ACMEv1, which Let’s Encrypt turned off in 2021-06 (sections 2.2 and 3.4 of the plan). - Why the old behavior could not be kept: the gem cannot be built with mruby 4 until pyama86/mruby-polarssl changes, and even built it could not get a certificate from Let’s Encrypt. Keeping it on
nextwould have kept a gem that no build of v3 can use, with an opt-in variable that ends in a stopped build. ngx_mruby 2.x keeps the gem. - What the documentation promised: docs/class_
and_ of 2.x calls auto-ssl an optional bundled mrbgem in an early phase of development and points to the scripts inmethod/README.md mrbgems/auto-ssl/mrblibfor its API. It says nothing about how long the gem is kept.
- The reason: decision 6 of the v3 plan (
- Affected: scripts that use
Nginx::SSL::ACME::ClientorNginx::SSL::ACME::Dehydrated, configurations built from the examples intest/conf/auto-ssl/, and builds that setNGX_MRUBY_AUTO_SSL=1. - What to do: get certificates from an ACME server with nginx’s own module ngx_
http_ (nginx-acme), or keep a 2.x build for a server that needsacme_ module Nginx::SSL::ACME; the documentation of 2.x describes the gem. RemoveNGX_MRUBY_AUTO_SSLfrom the environment of your builds: it has no effect.
Nginx::Upstream#server= and Nginx::Stream::Connection#upstream_server= raise ArgumentError for a string that cannot be a server (#680)
Section titled “Nginx::Upstream#server= and Nginx::Stream::Connection#upstream_server= raise ArgumentError for a string that cannot be a server (#680)”- Before: for an empty string or one of 256 bytes or more, and for a string with a NUL byte (since 2.7.3, entry 9 of the 2.7.3 release notes),
Nginx::Upstream#server=raisedArgumentErrorandNginx::Stream::Connection#upstream_server=raisedRuntimeError. For a string that nginx could not read as an address, such as192.0.2.1:notaport, both raisedRuntimeError, and so didupstream_server=for a host name. - Now: both raise
ArgumentErrorfor all of these. The messages stay (invalid upstream server (empty or too long),invalid upstream server (contains a NUL byte),invalid port in upstream 192.0.2.1:notaport), except for a host name, whose message isupstream server NAME is not an IP address or a unix: path. The server stays as it was, as before.RuntimeErroris left for a failure of nginx while it reads the string, and for an upstream with azone. - Why it changed:
- The reason: the same argument raised different classes in the two setters, and a script could not tell an argument that it can correct from a failure of nginx. The owner decided on this change for v3 (question 3 of the proposal).
- Why the old behavior could not be kept: keeping it would leave two rules for one kind of mistake. The 2.x line, which puts compatibility first, keeps them; v3 is the release that can change them.
- What the documentation promised: #648, for 2.7.3, wrote the old classes into
docs/class_and_method/README.md. The documentation of 2.7.2 said nothing about the exceptions (Nginx::Upstream#server=,Nginx::Stream::Connection#upstream_server=).
- Affected: scripts that rescue
RuntimeErroraroundNginx::Stream::Connection#upstream_server=, or aroundNginx::Upstream#server=for a string that nginx cannot read. Such arescueno longer catches the exception, and the handler ends with it: a handler of a request phase answers 500, andmruby_setleaves its variable empty. A script that rescuesArgumentErroraroundNginx::Upstream#server=now also catches these cases. - What to do: rescue
ArgumentError. A script for both versions rescuesArgumentErrorandRuntimeError, orStandardError. - Not changed by this release:
TypeErrorfor an argument that is not a String, andRuntimeErrorfor an upstream with azone, which is about the upstream and not about the argument.
Nginx::Upstream#server= raises ArgumentError for a host name instead of resolving it (#680)
Section titled “Nginx::Upstream#server= raises ArgumentError for a host name instead of resolving it (#680)”- Before:
Nginx::Upstream#server=resolved a host name with the system resolver when it was called and used the first address. The worker served no other client while it waited for the answer. A name that did not resolve raisedRuntimeError(host not found in upstream NAME). - Now: the method resolves nothing. A string that is not an IP address or a
unix:path raisesArgumentError(upstream server NAME is not an IP address or a unix: path), and the server stays as it was. The worker does not wait.Nginx::Stream::Connection#upstream_server=already refused a host name. - Why it changed:
- The reason: the design principle “No blocking” of AGENTS.md, which listed this setter among the places that block until this change. The owner decided on this change for v3 (question 3 of the proposal).
- Why the old behavior could not be kept: while the resolver answers, every other request of the worker waits, and a slow resolver stops the worker for as long as it takes. Resolving without waiting would need a resolver for scripts, which ngx_mruby does not have.
- What the documentation promised: #648, for 2.7.3, wrote the old behavior into
docs/class_and_method/README.md, said that the worker waits and said to give an IP address. The documentation of 2.7.2 said nothing about a host name.
- Affected: scripts that give
Nginx::Upstream#server=a host name,localhostincluded, and scripts that give it an IPv4 address in a form that only the system resolver read, such as127.1,2130706433or0x7f.0.0.1, or255.255.255.255; for those strings the worker did not wait. Unless the script rescues the exception, a handler of a request phase answers 500, andmruby_setleaves its variable empty. - What to do: give an IP address that the script has without waiting, for example from its configuration, and write an IPv4 address as four decimal numbers. For a name that does not change while nginx runs, write the name in the
serverline of theupstream {}block, which nginx resolves when it reads the configuration, and do not call the setter. nginx uses all the addresses of such a name: when it has more than one,Nginx::Upstream.newraisesRuntimeErrorfor that upstream, so remove that call too, or write an IP address in theserverline. A name that does not resolve stops nginx at start. - Not changed by this release: the 2.x line still resolves a host name. A host name in a
serverline of anupstream {}block, which nginx resolves, is not affected.
An access or post_read handler that waits in Nginx::Async.sleep ends as without the wait (#715)
Section titled “An access or post_read handler that waits in Nginx::Async.sleep ends as without the wait (#715)”- Before: when the timer of
Nginx::Async.sleepfired, ngx_mruby resumed the code and ended the handler itself, with the rules of the content phase instead of those of the handler’s phase. An access handler (undersatisfy allorsatisfy any) or a post_read handler that ended after the sleep without a result (noNginx.return,Nginx.send_headerorNginx.status_code=) or withNginx::OKlet the request reach its content, and nginx then closed the connection instead of answering the next request on it. Undersatisfy any, a 401 or 403 after the sleep ended the request with that status, where nginx tries the next access handler without the sleep. On a server whose earlier handler had storedNginx::DECLINED(see the entry “A handler that sets no result does not take the result of an earlier handler”), these ends were hidden. - Now: nginx calls the handler again when the sleep ends, the handler goes on with the code after the sleep, and the checker of the handler’s phase handles its result as for a handler that did not wait: without a result, an access handler goes on with the next access handler under
satisfy alland allows the request undersatisfy any, and a post_read handler goes on with the next phase; the next request on a kept-alive connection is answered. Undersatisfy any, a 401 or 403 after the sleep lets nginx try the next access handler, such asalloworauth_request. While the handler waits, nginx does not run its code again. - Why it changed:
- The defect: gap 2 of docs/proposals/archive/core-stabilization.md (section 2.3): the same code ended in another way after
Nginx::Async.sleepthan without it, because the timer replaced nginx’s phase checker with a copy of the content phase’s. The owner decided the design on 2026-11-01 (section 8, step 3). - Why the old behavior could not be kept: a script cannot rely on an end that depends on whether it waited, and closing the connection after the response drops the next request of a kept-alive client.
- What the documentation promised: Nginx::
Async of 2.7.3 said that the sleep is supported in access handlers and that the code after it runs, and said nothing about how the handler ends.#sleep
- The defect: gap 2 of docs/proposals/archive/core-stabilization.md (section 2.3): the same code ended in another way after
- Affected:
mruby_access_handler,mruby_access_handler_code,mruby_post_read_handlerandmruby_post_read_handler_codehandlers that callNginx::Async.sleep, in particular undersatisfy any, where an access handler that sleeps and then ends without a result now allows the request. - What to do: an access handler that sleeps and should deny the request returns
Nginx::HTTP_FORBIDDEN(orNginx::HTTP_UNAUTHORIZED) after the sleep. Undersatisfy any, nginx then tries the other access handlers, as without the sleep. - Tests: ports 18176 and 18178 (
test/conf/conf.d/82-async-resume-result.conf,test/t/cases/async_resume_result.rb: every end of access handlers undersatisfy all,satisfy any,satisfy anybeforeallow all, and beforeauth_request, and of post_read handlers, without a wait and after a sleep).
An access or post_read handler that writes output ends the request after the response (#715)
Section titled “An access or post_read handler that writes output ends the request after the response (#715)”- Before: an access or post_read handler that wrote output with
Nginx.rputsorNginx.echoand set no other status sent the response, and nginx then went on with the phases of the request: the content phase tried to answer again, nginx loggedheader already sent, and it closed the connection before it answered the next request on it. AfterNginx::Async.sleep, the same handler ended the request after the response. - Now: with or without a wait, the request ends after the response, as after the output of a rewrite or content handler, and nginx answers the next request on a kept-alive connection.
- Why it changed:
- The defect: the handler returned
NGX_OKto nginx after the response, which the access and post_read phases read as “go on”. This is the end of a run with output that step 3 of section 8 of docs/proposals/archive/core-stabilization.md makes the same with and without a wait. - Why the old behavior could not be kept: the response of the handler was already sent, and the later phases could only fail on it and close the connection.
- What the documentation promised: Nginx.rputs of 2.7.3 said “Puts response text” for every handler, and said nothing about the phases after it.
- The defect: the handler returned
- Affected:
mruby_access_handler*andmruby_post_read_handler*handlers that write output, and log monitoring of theheader already sentlines that they caused. - What to do: nothing; a handler that wrote output to answer the request now answers it once.
- Tests: ports 18176, 18178 and 18179 (
test/t/cases/async_resume_result.rbandtest/t/cases/async_result_isolation.rb, the cases “that ends with output”).
A handler that sets no result does not take the result of an earlier handler (#715)
Section titled “A handler that sets no result does not take the result of an earlier handler (#715)”- Before:
Nginx.return,Nginx.send_headerandNginx.status_code=stored their value in the status of the response, also a return code below 0 such asNginx::DECLINED, and a later handler of the same request that set no result returned that value. On a server whosemruby_server_rewrite_handlerreturnedNginx::DECLINEDfor every request, a content handler that ended without output and without a status went on to the next content handler or to the static module, which answered 404 when no file matched; undersatisfy any, an access handler without a result was taken to have declined, anddenyrefused the request with 403. After a handler that its timer resumed (Nginx::Async.sleep) or that the end of its subrequest resumed, ngx_mruby itself stored 500 for every result butNginx::OK,Nginx::DECLINEDincluded, so that a later content handler without output and without a status answered 500. - Now: the result of a handler is its own. A handler that sets none has no result, whatever an earlier handler of the request set: a content handler of the main request without output answers 200 with an empty body (see “A content handler that ends without output answers 200 with an empty body instead of 500”), and an access or post_read handler goes on as with
Nginx::OK. A rewrite or server rewrite handler without a result goes on to the next phase handler (see “A rewrite or server rewrite handler that ends without a result goes on to the next phase handler”). - Why it changed:
- The defect: gap 3 of docs/proposals/archive/core-stabilization.md (section 2.1): what a handler did depended on handlers that it does not contain, and the same script behaved in another way on two servers. The owner decided on 2026-11-01 that the result of a handler is its own (Q6 of section 9).
- Why the old behavior could not be kept: a script cannot see what an earlier handler of the request returned, so it cannot know how it ends without a result.
- What the documentation promised: Nginx.return of 2.7.3 said that it returns a status to the client or controls nginx’s request processing, and did not say that the value carries over to later handlers.
- Affected: configurations with an
mruby_server_rewrite_handler*,mruby_rewrite_handler*,mruby_post_read_handler*ormruby_access_handler*that returnsNginx::DECLINEDor another value for every request, together with a content handler that can end without output and without a status, or an access handler undersatisfy anythat can end without a result. - What to do: a content handler that should go on to the next content handler returns
Nginx::DECLINEDitself; an access handler undersatisfy anythat should leave the decision to the other access handlers returnsNginx::DECLINEDitself. - Tests: port 18179 (
test/conf/conf.d/82-async-result-isolation.conf,test/t/cases/async_result_isolation.rb: a server rewrite handler returnsNginx::DECLINED, and the later access and content handlers end by their own result).
An mruby_set handler that waits in Nginx::Async.sleep sets its variable, and the request goes on (#715)
Section titled “An mruby_set handler that waits in Nginx::Async.sleep sets its variable, and the request goes on (#715)”- Before: when the sleep ended, ngx_mruby set the variable and then ended the request without a response, unless an earlier handler of the request had stored
Nginx::DECLINED(as the server rewrite handler of a server that returns it for every request). A status that the code set withNginx.returnafter the sleep ended the request with that status; without the sleep, such a status does not end it. - Now: when the code returns, the variable is set and the request goes on with the next handler of the phase, as without the sleep, so the later phases read the value (a content handler,
proxy_pass). A status that the code sets does not end the request. An exception after the sleep answers 500, as before. - Why it changed:
- The defect: gap 2 of docs/proposals/archive/core-stabilization.md (section 2.3): the end of an
mruby_sethandler after the sleep depended on a status stored by another handler (section 4.4 of the proposal, step 3 of section 8, decided by the owner on 2026-11-01). - Why the old behavior could not be kept: a request that ends without a response leaves the client waiting until a timeout, and the end of the handler cannot depend on handlers that it does not contain.
- What the documentation promised: Nginx::
Async of 2.7.3 said that the sleep is supported in set handlers, and said nothing about how the request goes on.#sleep
- The defect: gap 2 of docs/proposals/archive/core-stabilization.md (section 2.3): the end of an
- Affected:
mruby_setandmruby_set_codewhose code callsNginx::Async.sleep. - What to do: nothing for most configurations. Code that ended the request with a status after the sleep returns that status from a later handler instead, for example a rewrite handler that reads the variable. The directives of the same rewrite script after the
mruby_setstill run before the sleep ends, without the value. - Tests: port 18182 (
test/conf/conf.d/83-async-set-var.conf,test/t/cases/async_set_var.rb).
A rewrite or server rewrite handler that ends without a result goes on to the next phase handler (#720)
Section titled “A rewrite or server rewrite handler that ends without a result goes on to the next phase handler (#720)”- Before: an
mruby_rewrite_handler*ormruby_server_rewrite_handler*handler that ended without output and withoutNginx.return,Nginx.send_headerorNginx.status_code=, or withNginx.return Nginx::OK, returnedNGX_OKto the rewrite phase, and nginx finalized the request without a response: withConnection: closeit closed the connection without a byte, and a kept-alive connection stayed open untilkeepalive_timeout;error.loghad no line at theerrorlevel. On a server whose earlier handler had returnedNginx::DECLINEDfor every request, such a handler took that value and went on.Nginx.returnwith a return code below 0, such asNginx::DECLINED, also stored the code in the status of the response. - Now: such a handler goes on to the next phase handler, as with
Nginx::DECLINED, with or without a wait inNginx::Async.sleeporNginx::Async::HTTP.sub_request, whatever an earlier handler of the request set. A return code below 0 is the result of the handler only, and the status of the response does not change. A handler with output, with a status from 100 up or with an exception ends as before. - Why it changed:
- The defect: gap 1 of docs/proposals/archive/core-stabilization.md (section 2.3): an end without a response helps no script. The owner decided on 2026-10-04 that a rewrite handler that ends with no output and no
Nginx.returngoes on, as withNGX_DECLINED, onnext(decision (b), recorded in docs/HANDOFF.md), and extended it to server rewrite handlers on 2026-11-01 (Q6 of section 9 of the proposal). - Why the old behavior could not be kept: the client got no response at all, and nothing in
error.logsaid why. - What the documentation promised: the documentation of 2.7.3 did not say what a rewrite handler without
Nginx.returndoes.
- The defect: gap 1 of docs/proposals/archive/core-stabilization.md (section 2.3): an end without a response helps no script. The owner decided on 2026-10-04 that a rewrite handler that ends with no output and no
- Affected:
mruby_rewrite_handler*andmruby_server_rewrite_handler*handlers that can end without a result or withNginx::OK, for example a handler that only sets variables or headers; they now let the request go on to the content of the location. The test of 2.x behavior “rewrite handler without output or DECLINED sends no response” intest/t/cases/request_api.rbexpects the content handler’s 200 now. - What to do: nothing for a handler that should let the request go on; a handler that should end the request returns the status it means, for example
Nginx.return Nginx::HTTP_FORBIDDEN. - Tests: ports 18176, 18177 and 18179 (
test/t/cases/async_resume_result.rbandtest/t/cases/async_result_isolation.rb: rewrite and server rewrite handlers without a result and withNginx::OK, without a wait, after a sleep and after a subrequest), and port 18111 (test/t/cases/request_api.rb).
Nginx::Async::HTTP.sub_request works in a content handler, also after Nginx::Async.sleep (#722)
Section titled “Nginx::Async::HTTP.sub_request works in a content handler, also after Nginx::Async.sleep (#722)”- Before: since 2.7.3,
Nginx::Async::HTTP.sub_requestin a content handler (mruby_content_handler*) that had waited inNginx::Async.sleepraised aRuntimeError(Nginx::Async::HTTP.sub_request is not available after Nginx::Async.sleep in a content handler), and the request got 500. Without a sleep before, a content handler could call it, although the documentation named only the set, rewrite and access handlers. - Now: a content handler waits for the subrequest, before or after a sleep, and answers with the output or the status that its code sets after the call; nginx answers the next request on a kept-alive connection.
- Why it changed:
- The defect: gap 4 of docs/proposals/archive/core-stabilization.md (section 2.3). 2.7.3 raised there because nothing would finalize the request after the subrequest. Since the end of a subrequest wakes the request through nginx, which calls the handler again (gap 5, step 5 of section 8), the checker of the content phase finalizes it. The owner decided on 2026-11-01 that 3.0.0 supports it (Q1 of section 9).
- Why the old behavior could not be kept: a content handler that answers from a subrequest is the base of the plan’s row on calls from a handler to other services, and the raise is not needed any more.
- What the documentation promised: Nginx::
Async:: of 2.7.3 said that it raises in a content handler after a sleep, and entry 2 of the 2.7.3 release notes said the same.HTTP #sub_ request
- Affected: content handlers that call
Nginx::Async::HTTP.sub_requestafterNginx::Async.sleep, and code that rescued itsRuntimeError. - What to do: remove such a
rescue; the call returns the response of the subrequest. - Tests: ports 18133 (
test/t/cases/async_sleep_in_content.rb, the case “Nginx::Async:: HTTP .sub_ request after a sleep in a content handler waits for the subrequest, and the handler answers”) and 18183 ( test/conf/conf.d/84-async-subrequest-return.conf,test/t/cases/async_subrequest_return.rb).
A handler that waits for Nginx::Async::HTTP.sub_request runs its code once and ends as without the wait (#722)
Section titled “A handler that waits for Nginx::Async::HTTP.sub_request runs its code once and ends as without the wait (#722)”- Before: when the subrequest ended, ngx_mruby resumed the code inside the end of the subrequest and ended the handler there, with the rules of the content phase instead of those of the handler’s phase. While it waited, the handler returned
NGX_AGAIN; for an access or post_read handler, nginx then ran the phases of the request again when it went on after the subrequest, which ran the handler’s code again from its start, with another subrequest. - Now: the handler returns
NGX_DONEwhile it waits, and nginx ignores the events of the request until the subrequest ends. Then nginx wakes the request and calls the handler again, which goes on with the code after the call, and the checker of the handler’s phase handles its result as for a handler that did not wait. The code of the handler runs once for the request, and its subrequest is sent once. - Why it changed:
- The defect: gap 5 of docs/proposals/archive/core-stabilization.md (section 2.3): the end of the subrequest and the end of the parent’s handler ran as one call, outside nginx’s phase checker. Step 5 of section 8, decided by the owner on 2026-11-01, moves the resume into the parent’s own run of the phases.
- Why the old behavior could not be kept: a handler whose code runs again repeats what the code does, its subrequest included, and its end depended on the handler kind of another phase.
- What the documentation promised: Nginx::
Async:: of 2.7.3 said “Sends a sub request in non-blocking way” and that it is supported in access handlers, and nothing about how the handler ends.HTTP #sub_ request
- Affected:
mruby_access_handler*andmruby_post_read_handler*handlers that callNginx::Async::HTTP.sub_request, and the other handlers that call it, whose results nginx now handles in their own phase. - What to do: nothing for most scripts. A script that counted on its code running again after the subrequest does the work after the call instead, where the response of the subrequest is available.
- Tests: ports 18176 to 18179 (
test/t/cases/async_resume_result.rbandtest/t/cases/async_result_isolation.rb: every end of access, post_read and content handlers after a subrequest), and ports 18183 and 18184 (test/t/cases/async_subrequest_return.rb: an access or post_read handler that waits for a subrequest and sets no result, or returnsNginx::DECLINED, runs once, sends one subrequest, and the request goes on).
A UDP stream session runs its code once: datagrams that arrive while the code waits do not start it again (#727)
Section titled “A UDP stream session runs its code once: datagrams that arrive while the code waits do not start it again (#727)”- Before: nginx called the stream handler for each datagram from the client of a UDP session (
listen ... udp), and while the code of the session waited inNginx::Stream::Async.sleep, each datagram started the code again from its start, in another fiber of the same session. The sleep of the newer run replaced the pending one, so only the last run went on after its sleep. - Now: a session runs its code once. A datagram that arrives while the code waits does not start it again; nginx gives the datagram to the handler only during that call, so the code does not see it. The first datagram remains available to the next phase; payloads received during each wait are discarded and are not queued or replayed. Once the session reaches
proxy_pass, subsequent datagrams are handled normally. The session goes on, or ends, by the result of the code after the sleep, as for a session whose code does not wait. - Why it changed:
- The defect: gap 9 of docs/proposals/archive/core-stabilization.md (section 2.5): the code of a session ran several times at once, in fibers of one session. The owner decided on 2026-11-01 that a UDP session runs its code once (Q4 of section 9).
- Why the old behavior could not be kept: the runs shared the session and its result, and only the last one decided how the session went on.
- What the documentation promised: Nginx::
Stream:: of 2.7.3 said that the session goes on after the sleep by the result of the code, and nothing about datagrams during the sleep.Async #sleep
- Affected:
mruby_streamandmruby_stream_codeof alisten ... udpserver whose code callsNginx::Stream::Async.sleepand whose clients send more than one datagram during the sleep. - What to do: nothing for most configurations. Code that counted on running once for each datagram does not sleep, or handles one datagram per session.
- Tests: port 12392 (
test/conf/conf.d/stream/47-async-sleep-udp-once.conf,test/t/cases/stream_async_sleep_udp_once.rb) checks one, ten and then one datagram in separate sessions, with one start, one resume and the exact reply in each.test/t/cases/stream_async_sleep_udp_session.rbchecks consecutive waits, exact proxy payloads and shutdown on ports 12393-12396.
A stream session that waits when worker_shutdown_timeout expires ends then (#727)
Section titled “A stream session that waits when worker_shutdown_timeout expires ends then (#727)”- Before: when
worker_shutdown_timeoutexpired in a worker that shut down (after a reload or SIGQUIT), nginx marked the connections to be closed and called their read handlers, but a stream session whose code waited inNginx::Stream::Async.sleepwent on: the code ran again from its start in another fiber, and the worker ran until the code ended. - Now: such a session ends when the timeout expires. The code after the sleep does not run,
error.loggets the lineshutdown timeoutat theinfolevel, and the worker exits, as it does for a session ofproxy_pass. - Why it changed:
- The defect: gap 10 of docs/proposals/archive/core-stabilization.md (section 2.5): the handler did not look at the close that nginx asks for, so
worker_shutdown_timeoutdid not bound the life of an old worker with such a session. Step 6 of section 8, decided by the owner on 2026-11-01. - Why the old behavior could not be kept:
worker_shutdown_timeoutis the setting that bounds how long an old worker runs after a reload. - What the documentation promised: the documentation of 2.7.3 said nothing about
worker_shutdown_timeoutand stream code that sleeps.
- The defect: gap 10 of docs/proposals/archive/core-stabilization.md (section 2.5): the handler did not look at the close that nginx asks for, so
- Affected: stream servers whose code calls
Nginx::Stream::Async.sleep, in configurations withworker_shutdown_timeout. - What to do: nothing; code that must finish keeps its sleeps shorter than
worker_shutdown_timeout. Withoutworker_shutdown_timeout, an old worker still finishes the sleeps in flight. - Tests:
test/t/cases/workers.rb, modeshutdown(test/conf/workers/shutdown.conf, ports 18185 and 12393).
Nginx::Stream::Connection.proxy_protocol_addr and proxy_protocol_ip return nil for a connection without a PROXY source address
Section titled “Nginx::Stream::Connection.proxy_protocol_addr and proxy_protocol_ip return nil for a connection without a PROXY source address”- Before: with nginx 1.17.6 and later,
Nginx::Stream::Connection.proxy_protocol_addrandNginx::Stream::Connection.proxy_protocol_ip, as class and as instance methods, did not return a value for a connection that had no source address from a PROXY protocol header: on a listen withoutproxy_protocol, and after the headerPROXY UNKNOWN(version 1) or a version 2 header with the commandLOCAL. - Now: the methods return
nilfor such a connection. After a header that carries addresses, they return its source address as before. 2.7.4 makes the same change. - Why it changed:
- The defect: the methods returned no value for such a connection, as “Before” describes. The advisory GHSA-xjh6-6vgm-56wj describes the defect, the affected versions and the conditions.
- Why the old behavior could not be kept: such a connection has no address to return, and
niltells it apart from a connection with one. In HTTP code,Nginx::Var#proxy_protocol_addrreturnsnilin the same case. - What the documentation promised: the methods were not documented. docs/class_
and_ describes them now.method/README.md
- Affected:
mruby_streamandmruby_stream_codecode that calls these methods on a connection without a PROXY source address. - What to do: nothing for code that compares the result with a String. Code that calls a String method on the result handles
nil, for example withto_s. - Tests: ports 12385 and 12386 of the mode
stream_masteroftest/t/cases/_second_instance.rb, a second nginx with a master process and one worker.
On a listen with proxy_protocol, a stream session whose code sleeps reads nothing from the client, and worker_shutdown_timeout ends it
Section titled “On a listen with proxy_protocol, a stream session whose code sleeps reads nothing from the client, and worker_shutdown_timeout ends it”- Before: while the code of a session on a listen with
proxy_protocolwaited inNginx::Stream::Async.sleep, the read events of the connection were handled as before the code ran: bytes that the client sent during the sleep could end the session (status 400 in the access log), and whenworker_shutdown_timeoutexpired during the sleep, the session did not end then. - Now: while the code sleeps, nginx reads nothing from the client on such a listen, as on the other listens. The bytes that the client sends then stay for the phase after the code:
proxy_passsends them to the upstream. A client that closes the connection during the sleep is seen by the phase after the code, as on the other listens. Whenworker_shutdown_timeoutexpires during the sleep, the session ends, as the entry “A stream session that waits whenworker_shutdown_timeoutexpires ends then” describes. 2.7.4 makes the same change for TCP sessions. - Why it changed:
- The defect: the read events during the sleep were handled as before the code ran, as “Before” describes. The advisory GHSA-xjh6-6vgm-56wj describes the defect, the affected versions and the conditions.
- Why the old behavior could not be kept: the bytes after the header belong to the protocol that the later phases carry. A session that does not end at
worker_shutdown_timeoutkeeps the old worker process after the time that the directive sets. - What the documentation promised: docs/class_
and_ said nothing about reads during the sleep. nginx’s documentation ofmethod/README.md worker_shutdown_timeoutsays that nginx tries to close the open connections when the timeout expires.
- Affected: stream servers on a listen with
proxy_protocolwhosemruby_streamormruby_stream_codecode callsNginx::Stream::Async.sleep: the clients that send bytes or close the connection during the sleep, and a worker that shuts down (a reload, an upgrade, a stop) withworker_shutdown_timeoutwhile the code sleeps. - What to do: nothing. The phase after the code gets the bytes of the client, as on a session whose code does not sleep.
- Tests: port 12384 (
test/conf/conf.d/stream/48-proxy-protocol-wait.conf,test/t/cases/stream_proxy_protocol_wait.rb: the reply after bytes during the sleep), and ports 12387 and 12388 of the modestream_masteroftest/t/cases/_second_instance.rb(sessions with and withoutproxy_protocolwhenworker_shutdown_timeoutexpires).
Nginx.redirect with a local URI takes effect when the handler ends (#728)
Section titled “Nginx.redirect with a local URI takes effect when the handler ends (#728)”- Before:
Nginx.redirectwith a local URI made the internal redirect inside the call: nginx ran the phases of the target location there, and its mruby handlers ran inside the fiber of the calling handler. The calling handler went on after the call and returned its own result, so two handlers could answer one request: output or a status that the calling handler set after the call answered first and the target’s output followed it, a content handler of the target ended the request atNginx::Async.sleepwithout its output, and after a sleep andNginx.redirectin a content handler the client got the target’s 200 while the access log had 500. An exception of the calling handler after the call left the target’s answer. - Now: in a post_read, server rewrite, rewrite, access or content handler, the call records the URI, the code goes on to its end, and then nginx runs the phases of the target, whose handlers run outside the caller’s fiber and can wait like any handler. One handler answers the request. The output and the status of the calling handler are not sent; when its code writes output or sets a status after the call,
error.loggets a line at thewarnlevel that ends withset after Nginx.redirect are not sent. Response headers that the calling handler sets and changes that it makes to the request (its arguments, for example withNginx::Request#args=) stay, also when they come after the call: the target’s answer carries those headers, and the target sees those arguments. An exception of the calling handler answers 500, and the redirect does not take effect.Nginx.redirectwith a URL, and a local redirect from anmruby_set*handler, a log handler or a filter, are unchanged. - Why it changed:
- The defect: gap 6 of docs/proposals/archive/core-stabilization.md (section 2.4): the three cases above. The owner decided on 2026-11-01 that
Nginx.redirecttakes effect when the handler ends (Q2 of section 9). - Why the old behavior could not be kept: two handlers that answer one request send two responses or none, and a target that waits ran inside another handler’s fiber.
- What the documentation promised: Nginx.redirect of 2.7.3 said that the internal redirect runs the handlers of the other location before the call returns, and that the calling code goes on after the call.
- The defect: gap 6 of docs/proposals/archive/core-stabilization.md (section 2.4): the three cases above. The owner decided on 2026-11-01 that
- Affected: handlers that call
Nginx.redirectwith a local URI and then write output, set a status, set response headers, change the arguments of the request or raise, handlers that rely on the target having run when the call returns, and log monitoring of the 500 in the access log of a redirected request. - What to do: write nothing after
Nginx.redirectthat is meant for the client; return from the handler after the call when the code after it should not run. Code that read what the target set (a variable, a header) after the call moves to the target. - Tests: port 18186 (
test/conf/conf.d/85-redirect-async.conf,test/t/cases/redirect_async.rb), and the cases oftest/t/cases/async_sleep_in_content.rbandtest/t/cases/async_exception_state.rbwithNginx.redirect.
Nginx.rputs, Nginx.echo, Nginx.redirect and Nginx::Filter#body= raise TypeError when to_s of the argument does not return a String (#776)
Section titled “Nginx.rputs, Nginx.echo, Nginx.redirect and Nginx::Filter#body= raise TypeError when to_s of the argument does not return a String (#776)”- Before:
Nginx.rputs,Nginx.echo,Nginx.redirect,Nginx::Filter#body=andNginx::Filter#outputconverted an argument that is not a String with itsto_sand used the result as a String without checking its type. Up to 2.7.5, ato_sthat returns an Integer ended the worker process with a segmentation fault, with the other requests of that worker, and ato_sthat returns another object that is not a String made the method read the memory of that object as a String. Ato_sthat is missing or raises made these methods raise its exception, as it does now. 2.7.6 (#775) makes the same change as this entry. - Now: these methods raise
TypeError(... cannot be converted to String) whento_sof the argument returns something other than a String, as the setter ofNginx::Vardoes (#735). The exception ends the handler like any other exception of the script: arescuein the script catches it, and otherwise ngx_mruby logs it and the request gets 500. Nothing is written, no redirect is made, and the body of the filter stays as it was. - Why it changed:
- The defect: these methods read the result of
to_sas a String without checking its type. #735 fixed the same reading formruby_setandNginx::Var, and the tests of the 2.x form of that change (#768) found it in these methods. - Why the old behavior could not be kept: the old behavior ended the worker process, with the other requests of that worker, or read memory that was not a String. These methods need a String, and such a value gives none, so they raise the exception that the setter of
Nginx::Varraises for the same value. - What the documentation promised: Nginx.rputs in 2.7.5 said that an argument that is not a String is converted with
to_s, and said nothing about ato_sthat does not return a String. The documentation ofNginx.echo,Nginx.redirectandNginx::Filter#body=said nothing about arguments that are not Strings.
- The defect: these methods read the result of
- Affected: calls of
Nginx.rputs,Nginx.echo,Nginx.redirect,Nginx::Filter#body=andNginx::Filter#outputwith an argument whoseto_sdoes not return a String. - What to do: pass a String,
nilor a value whoseto_sreturns a String to these methods. - Tests: port 18191 (
test/conf/conf.d/88-output-value-to-s.conf,test/t/cases/output_value_to_s.rb), the same cases as on 2.x (#775).
Nginx::Async::HTTP.sub_request raises a RuntimeError in an mruby_set handler (#735)
Section titled “Nginx::Async::HTTP.sub_request raises a RuntimeError in an mruby_set handler (#735)”- Before: in an
mruby_setormruby_set_codehandler,Nginx::Async::HTTP.sub_requeststarted the subrequest, but nginx did not wait for it. The directives after themruby_setand the later phases ran before the code had set the variable, and the code after the call ran when the subrequest ended. An exception of that code left the client without a response. - Now: the call raises a
RuntimeErrorwith the messageNginx::Async::HTTP.sub_request is not available in an mruby_set handler. The handler ends as after any exception there: without a wait,error.loggets the exception, the variable is empty, and the request goes on; afterNginx::Async.sleep, the request gets 500.Nginx::Async.sleepin anmruby_sethandler works as before. - Why it changed:
- The defect: gap 7 of docs/proposals/archive/core-stabilization.md (section 2.3): nginx does not wait for a subrequest of an
mruby_sethandler. The owner decided on 2026-11-01 that the call raises there (Q5 of section 9). - Why the old behavior could not be kept: the rewrite module runs an
mruby_sethandler inside its script and goes on when the handler returns, so the value of a handler that waits for a subrequest arrives after the phases that read it. A raise tells the script at once, as in log handlers since 2.7.1. - What the documentation promised: Nginx::
Async:: of 2.7.3 said that the method is supported inHTTP #sub_ request sethandlers, and Nginx.rputs of 2.7.3 said that nginx goes on without waiting for the variable and that an exception after the call leaves the client without a response.
- The defect: gap 7 of docs/proposals/archive/core-stabilization.md (section 2.3): nginx does not wait for a subrequest of an
- Affected:
mruby_setandmruby_set_codewhose code callsNginx::Async::HTTP.sub_request. - What to do: call
Nginx::Async::HTTP.sub_requestin a rewrite or access handler, which waits for the subrequest, and set the variable there withNginx::Var#set. - Tests: port 18182 (
test/conf/conf.d/83-async-set-var.conf,test/t/cases/async_set_var.rb: the cases withsub_request).
An mruby_set value that cannot be converted to a String answers 500 (#735)
Section titled “An mruby_set value that cannot be converted to a String answers 500 (#735)”- Before: ngx_mruby converted a value of an
mruby_setormruby_set_codehandler that is not a String with itsto_s, and used the result without checking that it is a String. Up to 2.7.5, a value whoseto_sreturned an object that is not a String ended the worker process with a segmentation fault, without a wait and afterNginx::Async.sleep. For a value withoutto_s, such as aBasicObject, and for a value whoseto_sraised, ngx_mruby read the exception object as a String, and the exception stayed in themrb_stateof the worker. With the values that #768 ran, aBasicObjectand a value whoseto_sraised, the request got 500 without a wait and ended without a response after the sleep; other values withoutto_swere not run. The next handler that the worker ran, in the same request or a later one, could fail with that exception. The setterNginx::Var#<name>=with a value, andNginx::Var#setwith a name or a value, whoseto_sreturned an object that is not a String ended the worker process; for ato_sthat is missing or raises, they raised its exception, as they do now. 2.7.6 (#768) checks the result ofto_sas well, but treats a value of the handler that cannot be converted as an exception of the code: without a wait the variable is empty and the request goes on with 200, and after the sleep the request gets 500. - Now: a value whose
to_sraises, is missing, or returns an object that is not a String ends the handler with the exception inerror.log, aTypeErrorfor the object that is not a String, and the request gets 500, without a wait and after a sleep.Nginx::Var#setandNginx::Var#<name>=raise that exception in the script. - Why it changed:
- The defect: the result of
to_swas used without the check, and an exception of the conversion was not handled where anmruby_sethandler ends after its code. - Why the old behavior could not be kept: a value that is not a String cannot become the value of an nginx variable, and the value of a script must not end the worker process. The same value also gave a different result depending on whether the code had waited: 500 or no response up to 2.7.5, and 200 with an empty variable or 500 on 2.7.6.
- What the documentation promised: mruby_set of 2.7.3 said that the directive sets a variable, and said nothing about a value that is not a String.
- The defect: the result of
- Affected:
mruby_setandmruby_set_codewhose code returns a value that is not a String and whoseto_sis missing, raises or does not return a String, andNginx::Var#setandNginx::Var#<name>=with such a name or value. - What to do: return a String from the code, for example with
to_son a value whoseto_sreturns a String, and give a class of your own ato_sthat returns a String. - Tests: port 18182 (
test/conf/conf.d/83-async-set-var.conf,test/t/cases/async_set_var.rb: the casesto_s_raises,no_to_s,to_s_not_stringandvar_set_not_string), and port 18189 (test/conf/conf.d/83-var-value-to-s.conf,test/t/cases/var_value_to_s.rb), the cases of the 2.x fix (#768) with the expectations of 3.0.0.
access_log writes the variables that mruby log handlers set, and the status that was sent (#770)
Section titled “access_log writes the variables that mruby log handlers set, and the status that was sent (#770)”- Before: ngx_mruby added its log handlers (
mruby_log_handlerandmruby_log_handler_code) at the end of the log phase, after the log handler of nginx’s log module, so nginx ran them afteraccess_loghad written the line of the request. The line had the values of the variables from before the log handlers: a variable that a log handler assigned withNginx::Varshowed the value that the request had before, for example the value of itsset. A log handler that raised set the status of the response to 500, and one that calledNginx.returnset that status;access_logdid not see either, but the log-phase handlers of the modules whose postconfiguration ran after ngx_mruby’s saw the changed status. - Now: the mruby log handlers run first in the log phase, before
access_logand before the log-phase handlers of the other modules whose postconfiguration runs before ngx_mruby’s. Modules whose postconfiguration runs later still add their log-phase handlers after them.access_logwrites the values that the log handlers assigned. After each mruby log handler, the status of the response is put back to the status that was sent, also when the handler raised or set a status, soaccess_logand the later log-phase handlers write the status that the client got. An exception of a log handler is still written toerror.log. - Why it changed:
- The reason: the agent proxy of v3 computes the cost and the tokens of a response in a log handler, and
access_loghas to write them on the line of the same request (item 15 of section 7 and the Pillar B row “Log handlers beforeaccess_log” of docs/proposals/v3-plan.md; section 2.10 of docs/proposals/core-alpha1.md). - Why the old behavior could not be kept: with the log handlers after
access_log, a value that a log handler computes cannot reach the access log line of its request. Moving them first without putting the status back would makeaccess_logwrite 500 after an exception of a log handler, for a response that the client got with another status. - What the documentation promised: mruby_
log_ of 2.7.5 said that the handlers are called at the end of request processing for logging, and said nothing about their order againsthandler access_log.
- The reason: the agent proxy of v3 computes the cost and the tokens of a response in a log handler, and
- Affected: an
access_logwhoselog_formatwrites a variable that an mruby log handler assigns, which now writes the assigned value; a log handler that changes a variable afteraccess_logwas meant to write it; log-phase handlers of other modules whose postconfiguration runs before ngx_mruby’s, which now run after the mruby log handlers; and log handlers that raise or set a status, whose status no longer reaches the later log-phase handlers. - What to do: nothing for most configurations. To log the value of a variable from before the log handler, copy it into another variable with
setin the location and write that variable. A log handler that passed a status to a later log-phase handler passes the value in a variable of its own instead. - Tests: port 18195 (
test/conf/conf.d/87-log-before-access-log.conf,test/t/cases/log_before_access_log.rb).
Nginx.redirect with a local URI raises a RuntimeError in a log handler (#770)
Section titled “Nginx.redirect with a local URI raises a RuntimeError in a log handler (#770)”- Before: in a log handler (
mruby_log_handlerandmruby_log_handler_code),Nginx.redirectwith a local URI made the internal redirect inside the call: nginx ran the phases of the target location there, and the code of the log handler went on after the call. - Now: the call raises a
RuntimeErrorwith the messageNginx.redirect with a local URI is not available in a log handler, and nginx makes no internal redirect. The log handler ends as after any other exception:error.loggets the exception, and the response, which was sent before the log phase, does not change.access_logwrites the status that was sent.Nginx.redirectwith a URL (http://,https://,$scheme) works in a log handler as before. - Why it changed:
- The reason: decision 1 of docs/proposals/core-alpha1.md (2026-11-09):
Nginx.redirectwith a local URI takes effect when the handler ends, and raises in a handler whose end cannot take it. With the change of the previous entry, the mruby log handlers run first in the log phase, andaccess_logand the other log-phase handlers then run on the same request. The internal redirect inside a log handler is therefore made an exception in this pull request. - Why the old behavior could not be kept: the log-phase handlers that run after the mruby log handlers run on the same request, so an internal redirect inside a log handler would run the phases of another location in the middle of the log phase.
- What the documentation promised: Nginx.redirect of 2.7.5 said that the method is designed to be used in the rewrite handlers, and that the internal redirect runs the handlers of the other location before the call returns. It said nothing about log handlers.
- The reason: decision 1 of docs/proposals/core-alpha1.md (2026-11-09):
- Affected: log handlers whose code calls
Nginx.redirectwith a local URI. - What to do: remove the call from the log handler. To send a request to another location, call
Nginx.redirectin a rewrite, access or content handler, where the redirect takes effect when the handler ends. - Tests: port 18195 (
test/conf/conf.d/87-log-before-access-log.conf,test/t/cases/log_before_access_log.rb: the case/redirect).
Output is sent with the status that the handler set, and error_page does not apply to it (#779, #783)
Section titled “Output is sent with the status that the handler set, and error_page does not apply to it (#779, #783)”- Before: a handler that wrote output with
Nginx.rputsorNginx.echoand then set a status withNginx.return,Nginx.send_headerorNginx.status_code=sent the output only with some statuses. A content handler of the main request sent it with 200 and with the statuses below 300 other than 201 and 204, a status below 200 included (since 2.7.2). For 201, 204 and the statuses from 300 up, nginx dropped the output and sent its own response for the status, and anerror_pageof the location for that status applied:Nginx.rputs '{"error":"no key"}'followed byNginx.return Nginx::HTTP_UNAUTHORIZEDanswered nginx’s 401 page, or the page of theerror_page. ForNginx::HTTP_CLOSE(444), nginx closed the connection without a response. In post_read, server rewrite, rewrite and access handlers and in subrequests, the output went out only with 200, or when no status was set after it. 201, 204 and the statuses from 300 up got nginx’s response in the same way, and for the other statuses below 300, for example 202 after output in an access handler, nginx ended the request without sending anything; a subrequest ended without a response body, and its parent read status 0. A status set before the first output did not apply to it: in every handler,Nginx.status_code = 401followed byNginx.rputssent the output with 200. - Now: in post_read, server rewrite, rewrite, access and content handlers, on the main request and in subrequests, also after
Nginx::Async::HTTP.sub_requestresumed the handler, output followed by a status from 200 up is sent with that status and theContent-Lengthof the output, as nginx’s ownreturn 401 "text";sends its text, without itsContent-Type. Anerror_pageof the location for the status does not apply to the response, as it does not apply to nginx’sreturnwith a text. For 301, 302, 303, 307 and 308, ngx_mruby adds noLocation. For 204 and 304, nginx sends the header without the output. A HEAD request gets the header with theContent-Lengthof the output. Output followed by a status below 200 answers 500 with nginx’s error page, through anerror_pagefor 500 if the location has one, without the output, anderror.loggets a line at theerrorlevel:status code <N> with the output is not the status of a final response. return NGX_HTTP_INTERNAL_SERVER_ERROR. A status set before the first output follows the same rule: the output goes out with it from 200 up, and a status below 200 answers 500. When a handler sets a status more than once, the last call decides, before or after the output. The exception isNginx::HTTP_CLOSE(444), nginx’s value for closing a connection without a response: with output before or after it, the output is not sent, and nginx closes the connection without a response, as for 444 without output. - Why it changed:
- The reason: decision 5 of docs/proposals/core-alpha1.md (2026-11-09): the output of a handler is sent with its status, as for the statuses other than 301, 302, 303, 307 and 308 nginx’s
returnwith a text does (section 2.12 there). Decision 6 there (2026-11-10) applies the same rule to a status set before the first output, as section 2.12 says (“before or after the output”), and decision 7 (2026-11-10) keeps 444 a way to drop a client: a client that the handler decided to refuse does not get the output built before that. The agent proxy of v3 answers 401, 403 and 429 with JSON bodies that Ruby builds, and item 8 of section 7 of docs/proposals/v3-plan.md accepted a body with any status as a behavior change of v3. - Why the old behavior could not be kept: a status set before the first output gives 200, and a status set after it dropped the output, so a script could not answer a status from 300 up with a body of its own, and whether its output was sent depended on the handler and on the status. Keeping 200 for a status set before the output would leave two rules for one call,
Nginx.return, whose result depended on where the script calls it. Lettingerror_pageapply when the location has one for the status would make what a script sends depend on directives elsewhere in the configuration. - What the documentation promised: Nginx.return of 2.7.5 described the old behavior of a content handler of the main request: 201, 204 and the statuses from 300 up got nginx’s own response without the output, and in a subrequest a status other than 200 after output ended the subrequest without a response body. It said nothing about the other handlers, and nothing about a status set before the output.
- The reason: decision 5 of docs/proposals/core-alpha1.md (2026-11-09): the output of a handler is sent with its status, as for the statuses other than 301, 302, 303, 307 and 308 nginx’s
- Affected: handlers that write output and then set 201, 204, 304 or a status from 300 up, and post_read, server rewrite, rewrite and access handlers and subrequests that write output and then set another status below 300 other than 200. A location with an
error_pagefor such a status now sends the output of the handler instead of the page of theerror_page. Handlers that set a status below 200 after output now answer 500 instead of that status. Handlers that set a status other than 200 before the first output, withNginx.return,Nginx.send_headerorNginx.status_code=, now send the output with that status instead of 200, or answer 500 for a status below 200; withNginx::HTTP_CLOSE(444), they close the connection without a response instead. In a subrequest, 444 with output closes the client’s connection, as nginx’s ownreturn 444does in the location of a subrequest and as 444 after the output did on 2.x; output written after 444 reached the parent with 200 before. Unchanged:Nginx::HTTP_CLOSEafter the output (the connection is closed without a response, as on 2.x), 0 and 200 before the first output (200 with the output), a return code below 0 before the first output (it does not apply to the output), output followed byNginx.redirectwith a URL (200 with the output and theLocation, also when the handler set a status before the output),Nginx::DECLINEDand the other return codes below 0 after the output (the output is not sent, and the phase gets the code), an exception (500 without the output),Nginx.return 0(no status; a content handler sends the output with 200), log handlers and output filters. - What to do: nothing for a handler that means to send its output with the status. A handler that relied on nginx’s page or on the
error_pageof the location sets the status without writing output, for exampleNginx.return Nginx::HTTP_UNAUTHORIZEDalone. A handler that sets 301, 302, 303, 307 or 308 after output setsLocationitself withNginx::Headers_out. A handler that sets a status below 200 with output sets the final status it means. A handler that sets a status before its output and means to send the output with 200 callsNginx.return Nginx::HTTP_OKafter the output. - Tests: port 18197 (
test/conf/conf.d/89-body-with-status.conf,test/t/cases/body_with_status.rb), port 18154 (test/t/cases/output_then_status.rb: the cases/created,/not_found,/continueand/sub_request_to_accepted, whose expectations change in #779, and/status_before_output, whose expectation changes in #783), and port 18110 (test/t/cases/request_api.rb: the casessend_header 404 after rputsandsend_header 201 after rputs, whose expectations change). On port 18138, the case of/deny_rputs_slowintest/t/cases/output_filters_with_content_handler.rbgets nginx’s 403 page fromdeny allafterNginx::DECLINED, because output followed byNginx.return 403is now sent.
A stream session or stream hook that raises logs the backtrace of the exception in a build with --with-debug (#796)
Section titled “A stream session or stream hook that raises logs the backtrace of the exception in a build with --with-debug (#796)”- Before: in an nginx built with
--with-debug, the HTTP module wrote the backtrace of an exception of Ruby code after itsmrb_run failedline, one line at theerrorlevel per frame (for example/path/to/handler.rb:10:in bar). The stream module wrote only themrb_run failedline for an exception ofmruby_stream,mruby_stream_init,mruby_stream_init_workerandmruby_stream_exit_worker, of their_codeforms, and ofmruby_stream_server_context_code. - Now: the stream module writes the backtrace in the same way: after the
mrb_run failedline, one line at theerrorlevel per frame, with the client and the server of the session for the code of a session. Themrb_run failedlines of both modules keep their text and their level. A build without--with-debug, whichbuild.shmakes by default, writes no backtrace, as before. - Why it changed:
- The reason: the two modules now write the exception of Ruby code with one function,
ngx_mrb_log_exceptioninsrc/common/ngx_mruby_log.c, so that both log it in the same way and a change of how an exception is logged is made once (section 2.8 of docs/proposals/core-alpha1.md). - Why the old behavior could not be kept: keeping stream without the backtrace would need a second path through the shared function for stream only, and an exception of a stream session would stay harder to locate than one of a request in the same debug build.
- What the documentation promised: the documentation of 2.7.5 said nothing about the backtrace in either module.
- The reason: the two modules now write the exception of Ruby code with one function,
- Affected: nginx built with
--with-debugand with stream code that raises:error.loggets more lines at theerrorlevel, one per frame of each exception, and alerts or log parsers that count the lines at theerrorlevel see more of them. - What to do: nothing for most builds. To count exceptions, match the
mrb_run failedlines instead of every line at theerrorlevel. - Tests: port 12380 (
test/conf/conf.d/stream/49-exception-log.conf,test/html/exception_log_stream.rb,test/t/cases/exception_log.rb).
An exception whose inspect raises or does not return a String is logged with the name of its class (#799)
Section titled “An exception whose inspect raises or does not return a String is logged with the name of its class (#799)”- Before: ngx_mruby writes an exception of Ruby code to
error.logwith theinspectof the exception, for examplemrb_run failed: return 500 HTTP status code to client: error: #<RuntimeError: boom>. When a script had redefinedinspectof the exception class so that it raised, or returned an object that is not a String, ngx_mruby wrote no such line: the handler still ended as after any exception (a request got 500, a stream session was closed), buterror.loghad no line of the exception. When the handler ran inside another mruby call, for example in the location thatNginx.redirectruns from anmruby_sethandler, aninspectthat raised did not return to the logging at all (see “Fixes”). - Now: the line is written in both cases, at the same level and with the same text before the exception, and names the class of the exception in place of its
inspect:error: #<MyError> (inspect raised ArgumentError)wheninspectraised (the class of the exception ofinspectcomes last), anderror: #<MyError> (inspect did not return a String)otherwise. The exception ofinspectitself is not logged. An exception whoseinspectreturns a String is logged as before. - Why it changed:
- The defect: when a script had redefined
inspectof an exception class so that it raised or returned an object that is not a String, the exception of the handler left no line inerror.log; and inside another mruby call, an exception ofinspectorbacktracewent on to the outer call past the nginx functions between the two calls, so that nginx did not finish the request (#799). The calls ofinspectandbacktracein the logging now run under the same protection as the resumed fiber inngx_mrb_fiber_resume(section 2.8 of docs/proposals/core-alpha1.md moved the logging intosrc/common/ngx_mruby_log.c). - Why the old behavior could not be kept: an exception that leaves no line in
error.logcannot be found from the log. With the protection, the logging gets the exception ofinspecton every path, so it can name the class instead of writing nothing. - What the documentation promised: the documentation of 2.7.5 said nothing about the line of an exception whose
inspectraises.
- The defect: when a script had redefined
- Affected: scripts that redefine
inspectof an exception class so that it raises or returns an object that is not a String.error.loggets one line at the level of themrb_run failedlines for each such exception (error, oremergformruby_stream_server_context_code). - What to do: nothing. To see the message of such an exception in
error.log, make itsinspectreturn a String. - Tests: port 18198 and the stream port 12382 (
test/conf/conf.d/93-exception-log-raising-methods.conf,test/conf/conf.d/stream/51-exception-log-raising-methods.conf,test/t/cases/exception_log_raising_methods.rb).
Methods that have no effect in a handler raise a RuntimeError there (#826)
Section titled “Methods that have no effect in a handler raise a RuntimeError there (#826)”-
Before: a method of the HTTP module checked only that a request was being processed, not which handler ran it. In a log handler, which runs after the response was sent, the setters of the request (
Nginx::Request#uri=,#args=,#method=,#request_line=,Nginx::Headers_in#[]=and#delete) changed the request, and the methods of the response head (Nginx::Headers_out#[]=and#delete,Nginx.status_code=,Nginx.returnandNginx.send_headerwith a status,Nginx::Request#content_type=) changed the response, without an effect on what the client got;Nginx.rputsandNginx.echoconverted their argument and returned. In header and body filters, which run while nginx sends the response, the setters of the request changed the request in the same way, and in a header filterNginx.rputsandNginx.echoadded their text to the output of the handler that started the response. In anmruby_sethandler,Nginx.rputsandNginx.echoadded their text to the output that a later handler of the location sent.Nginx::Filter#bodyoutside a body filter returned an empty String, or the body that a body filter of the request had read. In a handler that nginx runs after it has sent the response header, such as a handler of apost_actionlocation, the methods of the response head changed the response without an effect on what the client got, as in a log handler. -
Now: these calls raise a
RuntimeErrorwhose message names the method and the handler, for exampleNginx::Headers_out#[]= is not available in a log handlerorNginx.rputs is not available in a header filter, and the handler ends as after any other exception: a log handler logs it and the response stays as it was sent, a filter answers 500, and anmruby_sethandler logs it and gives the variable an empty value. The methods of the response head also raise in the other handlers once nginx has sent the response header (... is not available after the response header is sent).Nginx::Filter#bodyoutside a body filter raisesNginx::Filter#body can only be used in an output body filter, as#body=and#outputdid since 2.7.1; the message of#outputnow names#outputinstead of#body=. The table of “Where the methods work” in docs/class_and_ lists where each method works:method/README.md Methods Where they work New raise Reading the request: the getters of Nginx::Request,Nginx::Headers_in#[], the reads ofNginx::Var,Nginx::Connection, the getters ofNginx::Serverevery handler and filter of a request none Changing the request: uri=,args=,method=,request_line=,Nginx::Headers_in#[]=and#deletemruby_sethandlers, the post_read, server rewrite, rewrite, access and content handlerslog handlers, header and body filters Assigning variables: Nginx::Var#NAME=,#setevery handler and filter of a request none The response head: Nginx::Headers_out#[]=and#delete,Nginx.status_code=,Nginx.returnandNginx.send_headerwith a status,content_type=every handler and filter of a request but a log handler, while nginx has not sent the response header log handlers, and the other handlers after the response header is sent Output: Nginx.rputs,Nginx.echothe post_read, server rewrite, rewrite, access and content handlers, and body filters mruby_sethandlers, log handlers, header filtersThe body of a body filter: Nginx::Filter#body,#body=,#outputbody filters #bodyelsewhere (#body=and#outputraised there before)Outside a request, the methods of these rows raise
this method can only be used while processing a request, as since 2.7.1.Nginx::Async,Nginx::SSL,Nginx::Server#add_listener,Nginx.logand the methods of the stream module work where they worked, with the same messages.Nginx.redirectwith a local URI raises inmruby_sethandlers, log handlers and output filters (Nginx.redirect with a local URI is not available in ...), as the entries of #770 and #833 say, and works with a URL in every handler and filter of a request. -
Why it changed:
- The reason: item 8 of section 7 of docs/proposals/v3-plan.md accepted that a method called in a handler where it has no effect raises in v3, and section 2.1 of docs/proposals/core-alpha1.md gives each method the handlers where it works. A script that sets a response header in a log handler, or writes output in a header filter, learns from the exception that the call did nothing, instead of a response without the header or the text.
- Why the old behavior could not be kept: the methods found their request through a process-wide pointer and could not tell the handlers apart, so a call without an effect looked like one that worked. Each method now reads one execution context of the request, which says which handler runs; keeping the silent calls would leave a method that works in some handlers and does nothing in others without a sign of which.
- What the documentation promised: the documentation of the classes and methods of 2.7.5 said that the request-scoped methods raise outside a request, and said nothing about the handlers of a request where they have no effect.
-
Affected: log handlers (
mruby_log_handlerandmruby_log_handler_code) that set a response header or a status, write output, or change the request; output filters (mruby_output_header_filter*andmruby_output_body_filter*) that change the request, and header filters that write output;mruby_setandmruby_set_codehandlers that write output; handlers that run after nginx has sent the response header, such as those of apost_actionlocation, and set a response header or a status; and code that readsNginx::Filter#bodyoutside a body filter. Builds: ngx_mruby keeps the execution context inmrb->udof itsmrb_state, of the http module as of the stream module, so an mrbgem that puts a pointer of its own inmrb->udcannot be added to the build; on 2.x only the state of the stream module was like that. -
What to do: remove such calls, or move them to a handler where they work: set the response head in a phase handler or a filter, write output in a phase handler, and change the request in a phase handler or an
mruby_sethandler. A log handler that passes a value toaccess_logassigns a variable withNginx::Var, which works there. Abuild_config.rbof your own leaves out an mrbgem that setsmrb->ud(for example one that keeps a C pointer of its own there). -
Tests: port 18119 (
test/conf/conf.d/98-api-phases.conf,test/t/cases/api_phases.rb). The cases ofNginx::Filter#bodyin a header filter (port 18080,test/t/ngx_mruby.rb) and in a content handler (port 18112,test/t/cases/filter_connection.rb) now expect theRuntimeErrorinstead of an empty String. The log handlers of/directives/log(port 18114) write their output after they store their value. The case/post_actionof port 18119 checks the raise after the response header is sent.
Nginx.redirect with a local URI raises a RuntimeError in mruby_set handlers and output filters (#833)
Section titled “Nginx.redirect with a local URI raises a RuntimeError in mruby_set handlers and output filters (#833)”- Before: in an
mruby_setormruby_set_codehandler, an output header filter (mruby_output_header_filter*) and an output body filter (mruby_output_body_filter*),Nginx.redirectwith a local URI made the internal redirect inside the call: nginx ran the phases of the target location there, inside the Ruby call of the handler, and the code of the handler went on after the call. A handler of the target that waited inNginx::Async.sleeporNginx::Async::HTTP.sub_requestwas resumed by its timer or by the end of its subrequest, outside nginx’s phases, and a content handler there did not keep the request, so the request ended at the sleep. - Now: the call raises a
RuntimeErrorwith the messageNginx.redirect with a local URI is not available in an mruby_set handler(... in a header filter,... in a body filter), and nginx makes no internal redirect. The handler ends as after any other exception: anmruby_sethandler logs it and gives the variable an empty value, and the request goes on in its own location; a filter that does not rescue it answers 500.Nginx.redirectwith a URL (http://,https://,$scheme) works there as before. In a post_read, server rewrite, rewrite, access or content handler, Ruby code that runs outside the fiber of the handler, such as theinspectof its exception, raises as well (Nginx.redirect with a local URI is not available without a running handler fiber): it has no end that could take the redirect, which would otherwise be made inside that call. With the raise in log handlers (#770), only the post_read, server rewrite, rewrite, access and content handlers make an internal redirect, when they end (#728), and no handler of a request runs inside the Ruby call of another one. - Why it changed:
- The reason: decision 1 and section 2.9 of docs/proposals/core-alpha1.md (2026-11-09):
Nginx.redirectwith a local URI takes effect when the handler ends, and raises in a handler whose end cannot take it. Anmruby_sethandler runs inside the script of the rewrite module, which goes on after the handler, and a filter runs while nginx sends the response, so neither can end with a redirect. With no handler inside the Ruby call of another one, every wait of a handler ends through nginx’s phase checker, and the code that resumed a fiber from its timer or from the end of its subrequest outside nginx’s phases is removed. - Why the old behavior could not be kept: the handlers of the target ran inside the Ruby call of the calling handler, where nginx cannot call a handler that waits again, so such a wait ended the request outside nginx’s phases, and the calling handler went on with a request that the target was answering.
- What the documentation promised: Nginx.redirect of 2.7.5 said that the method is designed to be used in the rewrite handlers, and that the internal redirect runs the handlers of the other location before the call returns. It said nothing about
mruby_sethandlers or filters.
- The reason: decision 1 and section 2.9 of docs/proposals/core-alpha1.md (2026-11-09):
- Affected:
mruby_setandmruby_set_codehandlers, output header filters and output body filters whose code callsNginx.redirectwith a local URI, and Ruby code that ngx_mruby runs for a phase handler outside its fiber and that calls it, such as aninspector abacktracethat an exception class redefines. - What to do: call
Nginx.redirectwith a local URI in a rewrite or access handler, where the redirect takes effect when the handler ends. Anmruby_sethandler that chooses the target can return it as the value of its variable, for a rewrite handler or nginx’srewriteto redirect to. A filter cannot send the request elsewhere: choose the location before the response, in a phase handler. Do not callNginx.redirectfrominspectorbacktraceof an exception class. - Tests: port 18126 (
test/conf/conf.d/99-redirect-nested.conf,test/t/cases/redirect_nested.rb). The six cases oftest/t/cases/exception_log_raising_methods.rb(port 18198) andtest/t/cases/exception_log_script_methods.rb(port 18091) that logged an exception inside another mruby call, throughNginx.redirectfrom anmruby_sethandler, are removed, with the approval of the owner of 2026-11-16: no configuration can make such a call any more.
Assigning a variable that nginx does not know, or does not let scripts change, raises (#854)
Section titled “Assigning a variable that nginx does not know, or does not let scripts change, raises (#854)”- Before:
Nginx::Var#<name>=andNginx::Var#setwrote a line at theerrorlevel toerror.logand returnednilwhen nginx could not take the assignment, and the code and the request went on with the variable unchanged: for a name that nginx does not know (ngx_mruby ERROR ngx_mrb_var_set_vector:<line>: <name> is not found, withngx_mrb_var_set_funcforset), for a variable that nginx does not let scripts change, such as$urior$http_host(... <name> not changeable), and for a variable that nginx keeps no value of in the request (... <name> is not assinged). - Now: the assignment raises, and the message names the variable as the script wrote it:
NameErrorwithnginx variable $<name> is not defined (declare it with set or mruby_variable)for a name that nginx does not know, a name that begins with a prefix of nginx such asarg_orhttp_included;RuntimeErrorwithnginx variable $<name> cannot be changed by a scriptfor a variable that nginx does not let scripts change; andRuntimeErrorwithnginx variable $<name> cannot be assigned by a script: the configuration does not refer to itfor a variable without a set handler, such as one ofmaporgeo, that nothing in the configuration refers to, so that nginx keeps no value of it in the request. A handler that does not rescue the exception ends as after any other exception: its request answers 500 (a log handler logs the exception, after the response was sent), anderror.loghas themrb_run failedline of the exception. The worker goes on.nginx -tcannot find these mistakes, because the code decides the name when it runs; they show at the first request that runs the assignment. An assignment that nginx takes works as before, with the same value and the same return value.Nginx::Var#<name>=,Nginx::Var#setand the end of anmruby_sethandler that waited inNginx::Async.sleepassign through one function, which does what nginx’ssetdirective does. - Why it changed:
- The reason: decision 3 and section 2.3 of docs/proposals/core-alpha1.md (2026-11-09). A misspelled variable name, or an assignment to a variable that nginx does not let scripts change, now fails at the first request that runs it, with its exception in
error.log, instead of losing the value with only an error line while the request goes on. A handler that wants to go on rescues the exception, andmruby_variabledeclares every variable that a script means to assign, so a correct configuration does not reach it. - Why the old behavior could not be kept: the request went on as if the variable had the value, so a later handler,
proxy_passoraccess_logused the old value of the variable without a sign in the response, and the code that assigned it could not tell from the result alone whether anilcame from the failure; the two copies of the assignment also differed in how they converted and lowercased the name. - What the documentation promised: Nginx::
Var of 2.7.11 said that a variable has to be declared in nginx.conf and that a script cannot add one, and showedv.http_host = "192.168.0.1", an assignment to a variable that nginx does not let scripts change. It said nothing about what an assignment to such a variable does.
- The reason: decision 3 and section 2.3 of docs/proposals/core-alpha1.md (2026-11-09). A misspelled variable name, or an assignment to a variable that nginx does not let scripts change, now fails at the first request that runs it, with its exception in
- Affected:
Nginx::Var#<name>=(the accessors andmethod_missing) andNginx::Var#setin every handler and filter of a request, for a name that nginx does not know or a variable that it does not let scripts change or keeps no value of; log monitoring that matches the olderrorlines. Reading a variable is not affected:v.<name>still returnsnilfor a name that is not a variable. The end of anmruby_sethandler assigns a variable that its directive declared, which nginx takes. - What to do: declare the variables that scripts assign, with
setin the location, or withmruby_variablein thehttpblock, and assign them by their names; do not assign variables of nginx that scripts cannot change, such as$urior$http_host(to change the URI or a request header, use the setters ofNginx::RequestandNginx::Headers_in). A handler that should go on after a failed assignment rescuesNameErrorandRuntimeError. In log monitoring, match themrb_run failedline with#<NameError: nginx variable $or#<RuntimeError: nginx variable $in place of the old lines. - Tests: port 18107 (
test/conf/conf.d/99-var-assign.conf,test/t/cases/var_assign.rb). The cases/unknownoftest/t/cases/var_method_lookup.rband/set_shared_keyoftest/t/cases/var_input.rbexpectNameErrorwhere they expectednil.
nginx -t refuses a stream hook given twice in one context (#834)
Section titled “nginx -t refuses a stream hook given twice in one context (#834)”- Before: the stream module accepted a second directive for a hook in the same context, and the later one replaced the earlier one without a message:
mruby_streamandmruby_stream_codein oneserver {}(or in thestream {}block), either of them twice, and the file and the inline form ofmruby_stream_init,mruby_stream_init_workerandmruby_stream_exit_worker(for examplemruby_stream_initandmruby_stream_init_code) in thestream {}block. Only the code of the later directive ran. The HTTP module refused a second directive for the same code with"NAME" directive is duplicatedalready. - Now:
nginx -t, and a start or a reload of nginx, fail on the second directive with[emerg] "mruby_stream_code" directive is duplicated(the name is that of the second directive), as for the HTTP directives. One hook in thestream {}block and one in aserver {}are not a duplicate: the code of the server is the handler of the server, as before. When the file of a stream directive cannot be read or its code does not compile, theemergline has the form of the HTTP module,ngx_mruby-stream-module : ngx_stream_mruby_code_directive mrb_file(PATH) open failedor... mrb_string(CODE) load failed, instead ofmrb_string(PATH) load failedfor both forms. The same lines of the HTTP directives, and thecompile infoline at theinfolevel of both modules, name the directive function of the table (ngx_http_mruby_handler_directive,ngx_http_mruby_hook_directive,ngx_stream_mruby_code_directive) where they named a function of each directive, such asngx_http_mruby_rewrite_phase, with the same text otherwise and at the same level. - Why it changed:
- The reason: the code that a configuration means to run is the code that runs, and both modules set the code of a directive with one function and one rule,
ngx_mrb_code_setinsrc/common/ngx_mruby_code.c(decision 4 and section 2.5 of docs/proposals/core-alpha1.md). - Why the old behavior could not be kept: a configuration with two directives for a hook ran one of them without a word, so a hook left from an earlier edit, or added in an included file, replaced the code that the operator read in the configuration. Keeping the replacement would also keep a rule of its own for stream in the shared function.
- What the documentation promised: the directives of 2.7.5 said nothing about giving a stream hook twice.
- The reason: the code that a configuration means to run is the code that runs, and both modules set the code of a directive with one function and one rule,
- Affected: stream configurations with two of
mruby_streamandmruby_stream_codein one context, or with both forms ofmruby_stream_init,mruby_stream_init_workerormruby_stream_exit_worker, or one of them twice; nginx does not start or reload with them. Alerts or log parsers that match themrb_string(...) load failedline of a stream file directive, or the name of a directive function in theemerglines of the directives with Ruby code. - What to do: keep one directive of each hook in a context, the one whose code ran on 2.x (the later one), and remove the others. To match the error line of a directive whose code cannot be loaded, match
mrb_file(andmrb_string(, not the name of the function. - Not changed by this release:
mruby_stream_server_context_coderuns its code while nginx reads the configuration and keeps nothing, so each such directive of a server still runs. The HTTP directives keep their behavior, but for the function name in the lines above: the same arguments and contexts, a second directive for the same code is refused as before, and the file and the inline form of a phase handler are two handlers, which both run. - Tests:
test/t/cases/stream_duplicate_hooks.rb(nginx -twith port 12398) and the case ofmruby_stream_initandmruby_stream_init_codeintest/t/cases/stream.rb, which expects the refusal instead of the later hook.test/conf/nginx.stream.conf, the second nginx oftest/t/cases/_second_instance.rband thenginx -tcase oftest/t/cases/config_time_log.rbgive each stream hook once.
Output filters given at http or server level, or in a location, run in the locations below them (#835)
Section titled “Output filters given at http or server level, or in a location, run in the locations below them (#835)”- Before: an output filter (
mruby_output_header_filter,mruby_output_body_filterand their_codeforms) ran only at the level of its directive. One given in thehttp {}block ran for no request; one given in aserver {}block ran only for the requests of the server that matched none of its locations; one given in alocationran in that location, but not in the locations nested in it nor in itsifblocks. nginx copied the code of the filter to the levels below, but not the handler that runs it. The phase handler directives (mruby_rewrite_handlerand the others) given at those levels ran in the locations below them already. - Now: a location, a nested location or an
ifblock without a filter directive of its own runs the filter of the level above it: that of the location around it, of its server, or of thehttp {}block. The header filter and the body filter are inherited each on its own: a level with a directive of one kind runs its own filter of that kind instead of the one above it, and still runs the filter of the other kind from above, so a location with only a body filter runs the header filter of its server as well. Such a location reads its responses through the filter as the location of the directive does: with an mruby body filter, ngx_mruby setsr->filter_need_in_memory, so nginx reads a file of the response into memory, and the body filter sends the body that it made instead of the file; with a header filter alone, nginx passes the file on unread, and sends it withsendfilewhensendfileis on (#847); a body filter collects a body withContent-Lengthbefore its code runs, and holds the header until then; a body withoutContent-Length, such as a chunked response of an upstream, passes the body filter unread, with thenoticelinebody filter don't support chunked response, go to next filterinerror.log. Subrequests, such as those of SSI includes, run the filters of their locations in the same way. - Why it changed:
- The defect: a filter directive that nginx accepted in the
http {}andserver {}blocks did nothing in their locations, unlike the other directives with Ruby code of the same blocks. The merge of the location configuration,ngx_http_mruby_merge_loc_conf, merged the code of each filter but not the pointer to its handler, which only the directive set. Section 2.4 of docs/proposals/core-alpha1.md and the Pillar B row on the filter handler pointers of docs/proposals/v3-plan.md record it. - Why the old behavior could not be kept: a filter given for a server or for every server had no effect on the responses that its configuration named, and nothing reported it:
nginx -taccepted the directive, and the filter ran only for the requests that fell through every location. Keeping it would leave the filter directives the only directives with Ruby code that a level below does not inherit. - What the documentation promised: the directives of 2.7.5 gave
serverandlocationas the context of the four filter directives, as for the phase handlers, and said nothing about the locations of a server.
- The defect: a filter directive that nginx accepted in the
- Affected: configurations with a filter directive in the
http {}block or in aserver {}block, and those with a filter directive in alocationthat has nested locations orifblocks. The responses of those locations, also those that a static file, an upstream or areturnmakes, go through the filter: its code runs for each of them, a header filter changes their headers, and a body filter replaces their bodies. - What to do: check that each filter given at
httporserverlevel, and each filter of a location with nested locations orifblocks, can run for every response of the levels below it. A filter that should run in some locations only moves into those locations. A location keeps the filter of the level above it unless it gives a filter of the same kind of its own; there is no directive that turns an inherited filter off. - Not changed by this release: the phase handlers. ngx_mruby now adds to nginx’s phases only the handler of each phase and form (file or inline) that a directive of the configuration uses, with
mruby_add_handler oncounting as a content handler of the file form, where it added all twelve before. The handlers that are added run in the same order as before, and a handler that is not added would only have passed the request on, so no configuration or script sees a difference. - Tests: port 18108 (
test/conf/conf.d/99-filter-inherit.conf,test/t/cases/filter_inherit.rb), and the modehttp_filterof the second nginx oftest/t/cases/_second_instance.rb(port 18116) for a filter in thehttp {}block, a content handler that onlymruby_add_handler onuses and a log handler of one form.
A location with an mruby header filter and no body filter does not read files into memory (#847)
Section titled “A location with an mruby header filter and no body filter does not read files into memory (#847)”- Before: in a location with
mruby_output_header_filterormruby_output_header_filter_codeand withoutmruby_output_body_filterormruby_output_body_filter_code, ngx_mruby setr->filter_need_in_memory, as in a location with a body filter. nginx then read each file of a response, such as a static file, into memory, in the buffers ofoutput_buffers, before it passed the body on. Withsendfile on, the buffers kept the position of the file, and nginx sent their data withsendfileas before, but one set of those buffers at a time: a file larger than them was read and sent in pieces of their size. - Now: such a location passes a file of the response on unread, as a location without an mruby filter does: with
sendfile on, nginx sends it withsendfilewithout reading it first, andoutput_buffersdoes not apply to it. The status, the headers and the body that the client receives are the same. A location with an mruby body filter, its own or one that it inherits (#835), still gets its responses in memory, because the body filter reads the body from memory. - Why it changed:
- The defect: only the body filter reads the body; the header filter changes the headers and needs no body in memory, so the flag cost a read of every file of the response into memory that nothing in such a location used. The review of #835 reports the flag in such a location.
- Why the old behavior could not be kept: since #835, a header filter given at
httporserverlevel runs in every location below it, so one header filter, for example one that adds a header to every response, made nginx read every static file of the server into memory. - What the documentation promised: the directives of 2.7.5 said nothing about how nginx reads a file in a location with an output filter.
- Affected: locations with an mruby header filter and no mruby body filter, with
sendfile on, whose responses are files, such as static files: nginx no longer reads them into the buffers ofoutput_buffers, and sends them as a location without an mruby filter does. This does not apply where nginx already reads the file into memory for another reason: on an HTTPS connection without kernel TLS (r->main_filter_need_in_memory, set by nginx when the connection cannot usesendfile), and when a filter such as gzip, SSI or sub handles the response. Withsendfile off, nginx reads a file into those buffers in any case, and nothing changes. - What to do: nothing; the responses are the same.
- Tests:
test/t/cases/filter_sendfile.rb, with the modehttp_sendfileof the second nginx oftest/t/cases/_second_instance.rb(port 18116), which counts, for each request, the lines of nginx’s debug log for a read of the file into memory and for a call ofsendfile.
The measurement builds include stream sessions
Section titled “The measurement builds include stream sessions”- Before: the soak and callgrind builds omitted
--with-stream, and neither default set exercised a TCP stream session. The soak checked that the stream counter keys existed but did not judge their values. - Now: both measurement builds include stream. Their default sets add
stream_sleep, one TCP session that waits 1 ms and returns exact bytes through EOF. Soak samples check and printstream_timersandstream_fibers, and add asessionscolumn. The performance row reports instructions per completed session. - Why it changed:
- The reason: the planned stream coverage needs to observe pending timers and held fibers and measure the work of a completed wait.
- Why the old behavior could not be kept: an HTTP-only measurement binary cannot execute the stream handler or detect a change in its cost.
- What the documentation promised: the measurement rules described a comparison without stream support.
- Affected:
test/build_release.sh, the default soak and performance comparisons, and consumers of their reports. Runtime APIs,build.shandtest.share unchanged. - What to do: rerun both measurement scripts without
ONLY_RUNafter updating; the build stamp reconfigures and rebuilds both sides. Accept the additional soak columns and interpret the new performance row per TCP session. Keep the existing HTTP rows and thresholds when comparing results.
A HEAD response with an output body filter keeps its connection available
Section titled “A HEAD response with an output body filter keeps its connection available”- Before: a HEAD request to a location with
mruby_output_body_filterormruby_output_body_filter_code, whose response had a known content length, received its response headers, but nginx then closed the connection even when the headers advertised keep-alive. A following GET on that connection received no response. This occurred with both empty and nonempty replacement bodies. - Now: for those responses, after the HEAD headers are sent successfully, the filter sends no body bytes and leaves an otherwise reusable connection available for the next request. GET responses and header-filter errors keep their behavior. 204 and 304 responses through such a filter keep their connection as well (“A 204 or 304 response through an mruby output filter keeps its connection available” below).
- Why it changed:
- The defect: the body-filter finalizer returned
NGX_ERRORafter a successful header-only response. nginx treated that return as an output error and closed the connection. The review of #574 recorded the HEAD case, and the review of #628 confirmed it with a following GET. - Why the old behavior could not be kept: a successfully sent HEAD response did not represent an output error, and closing the connection prevented the next request advertised by keep-alive.
- What the documentation promised: Nginx::
Filter described replacement bodies and their content length, but did not describe a HEAD connection-close exception.#body=
- The defect: the body-filter finalizer returned
- Affected: HEAD responses with a known content length that are finalized by an mruby output body filter, when the connection can otherwise be kept alive.
- What to do: nothing. To close a connection deliberately, configure nginx’s keep-alive policy rather than relying on this filter error.
A HEAD response through an mruby header filter alone, or through a body filter without Content-Length, keeps its connection available (#848)
Section titled “A HEAD response through an mruby header filter alone, or through a body filter without Content-Length, keeps its connection available (#848)”- Before: a HEAD request to a location with
mruby_output_header_filterormruby_output_header_filter_codeand without an mruby body filter received the response header, with the changes that the header filter code made, and nginx then closed the connection, also when the header saidConnection: keep-alive. A request that the client sent next on that connection got no response. The same happened to a HEAD request to a location withmruby_output_body_filterormruby_output_body_filter_codewhose response had noContent-Length, such as a listing ofautoindexor a response of an upstream without a length; the body filter passes such a response on without running its code. Since #835, a header filter given athttporserverlevel runs in every location below it, so with such a filter every HEAD request to the server ended this way. - Now: after nginx has sent the header of such a HEAD response, ngx_mruby returns the result of sending it and passes no body on, as nginx’s own handlers do for HEAD, and nginx keeps an otherwise reusable connection for the next request. The header that the client receives is the same. GET responses and an error of the header filter code keep their handling. 204 and 304 responses on the same paths keep their connection as well (“A 204 or 304 response through an mruby output filter keeps its connection available” below).
- Why it changed:
- The defect: for a HEAD request, nginx’s header filter sets
r->header_onlywhen it sends the header. ngx_mruby passes the header on after the code of a header filter in a location without a body filter, and, in the body filter, for a response without a length; in both places it returnedNGX_ERRORwhen that flag was set, although the header had been sent. nginx’s handlers, such as the static file handler,returnandautoindex, return that result, so nginx ended the request as failed and closed the connection. The comment oftest/t/cases/head_body_filter.rbnames both paths as outside the fix of the body filter with a known length (“A HEAD response with an output body filter keeps its connection available” above). - Why the old behavior could not be kept: a HEAD response that nginx sent successfully is not an output error, and closing the connection lost the next request that keep-alive announced. Since #835, one header filter at
httporserverlevel, for example one that adds a header to every response, made every HEAD request to the server close its connection. - What the documentation promised: the directives of 2.7.10 said nothing about HEAD requests in a location with an output filter, or about closing the connection after one.
- The defect: for a HEAD request, nginx’s header filter sets
- Affected: HEAD requests to a location with an mruby header filter and no mruby body filter, its own or one that it inherits (#835), and HEAD requests to a location with an mruby body filter whose response has no
Content-Length, when the connection can otherwise be kept alive. - What to do: nothing. To close a connection deliberately, configure nginx’s keep-alive policy (
keepalive_timeout,keepalive_requests) instead of relying on this error. - Tests: port 18112 (
test/conf/conf.d/20-filter-connection.conf,test/t/cases/head_header_filter.rb): HEAD, and a GET control, through a header filter alone on a response ofreturnand on a static file, and HEAD through a body filter on a listing ofautoindex, also sent at 50 bytes a second (limit_rate 50) so that its header needs more than one write, each followed by a GET on the same connection, with a GET control of the listing.
A 204 or 304 response through an mruby output filter keeps its connection available (#849)
Section titled “A 204 or 304 response through an mruby output filter keeps its connection available (#849)”- Before: a response that ends at its header without a HEAD request, a 304 that nginx answers to a GET with
If-Modified-SinceorIf-None-Matchor a 204 such as that ofreturn 204;, received its header withConnection: keep-alivewhen it passed an mruby output filter, and nginx then closed the connection. A request that the client sent next on that connection got no response. This happened in a location withmruby_output_header_filterormruby_output_header_filter_codeand no mruby body filter, and in a location withmruby_output_body_filterormruby_output_body_filter_code, both when the response had aContent-Length(the 204 ofreturn 204;, which nginx gives the length 0) and when it had none (a 304 of a static file, whose length nginx removes). Since #835, a header filter given athttporserverlevel runs in every location below it, so with such a filter every conditional GET that nginx answered with 304 from a static file of the server ended this way. - Now: after nginx has sent the header of a response that ends at it (HEAD, 204 or 304), ngx_mruby returns the result of sending it and passes no body on, whatever the method of the request, as nginx’s own handlers do when the header ends the response. nginx keeps an otherwise reusable connection for the next request. The status and the header that the client receives are the same, and no body bytes follow the header. When nginx cannot send the header in one write, as with
limit_rateor a client that reads slowly, the branch for a response without a length passes nginx’s later calls on without the body, so the rest of the header goes out. A result ofNGX_ERRORfrom sending the header, and an error of the code of the header filter, keep their handling. - Why it changed:
- The defect: nginx’s header filter sets
r->header_onlywhen the status is 204 or 304, as it does for HEAD. The three places where ngx_mruby passes the header on (after the code of a header filter in a location without a body filter; in the body filter, for a response without a length; and after the code of a body filter, inngx_mrb_finalize_body_filter) returnedNGX_ERRORwhen that flag was set for a request other than HEAD, although the header had been sent. nginx’s handlers, such as the static file handler andreturn, return that result, so nginx ended the request as failed and closed the connection. The review of #848 recorded the 304 and the 204 with a header filter alone. - Why the old behavior could not be kept: a 204 or 304 that nginx sent successfully is not an output error, and closing the connection lost the next request that keep-alive announced. With a header filter at
httporserverlevel (#835), every conditional GET of a static file that the client could answer from its cache closed its connection. - What the documentation promised: the directives of 2.7.10 said nothing about 204 or 304 responses in a location with an output filter, or about closing the connection after one.
- The defect: nginx’s header filter sets
- Affected: 204 and 304 responses that pass an mruby output header filter or body filter, its own or one that the location inherits (#835), when the connection can otherwise be kept alive.
- What to do: nothing. To close a connection deliberately, configure nginx’s keep-alive policy (
keepalive_timeout,keepalive_requests) instead of relying on this error. - Tests: port 18112 (
test/conf/conf.d/20-filter-connection.conf,test/t/cases/header_only_keepalive.rb): a 304 of a static file to a GET withIf-Modified-Sinceand a 204 ofreturn 204;, each through a header filter alone and through a body filter, the 304 to GET and to HEAD of a static file that a body filter location reads through an output buffer smaller than the file (output_buffers 1 8), and a GET withoutIf-Modified-Sinceof each static file as the control, each followed by a GET on the same connection.
The integration test build enables Nginx::Debug
Section titled “The integration test build enables Nginx::Debug”- Before: the default
test.shbuild did not defineNGX_MRUBY_DEBUG_STATS, so handler scripts could not callNginx::Debug.statsorNginx::Debug.gcin that build. - Now:
test.shdefinesNGX_MRUBY_DEBUG_STATSfor nginx and ngx_mruby, enabling those methods and the counters they expose. The defaultbuild.shbuild and the performance comparison keep their existing flags. - Why it changed:
- The reason: the repeated-sleep integration test needs the pending-timer and held-fiber counters to check that one handler releases them after 1,000 waits.
- Why the old behavior could not be kept: leaving the counters out of the test binary would omit these assertions from the normal suite and its build-matrix cells.
- What the documentation promised: the test guide described
Nginx::Debugas absent from the defaulttest.shandbuild.shbuilds.
- Affected: binaries built by
test.sh, including static and dynamic module builds. Production builds made withbuild.shand the performance-comparison builds are unchanged. - What to do: for an existing test build, remove
build/nginx-X.Y.Z/objs/Makefile(build_dynamic/nginx-X.Y.Z/objs/Makefilefor a dynamic module, withX.Y.Zfromnginx_version), then runsh test.shwithoutONLY_BUILD_NGX_MRUBY; useBUILD_DYNAMIC_MODULE=1 sh test.shfor the dynamic build. This regenerates nginx’s configuration and recompiles with the counters before an incremental run. A fresh test build needs no extra step.
New features
Section titled “New features”Nginx::Async::HTTP.sub_requestreturns the response of the subrequest, anNginx::Async::HTTP::Responsewith the same status, headers and body asNginx::Async::HTTP.last_response; on 2.x it returnsnil(#722)- Scripts can use the additions of mruby 3.4, 4.0 and 4.1: pattern matching (
case/in), with strings as patterns since 4.1,Array#rfind, trailing commas in method parameters,&nilin method parameters, anditfor the first parameter of a block ([1, 2].map { it * 2 }is[2, 4]) (#561, #678) - Scripts can call methods that mruby 3.3.0 does not have, for example
Kernel#public_send,String#b,Hash#slice!,Array#fetch_values,Integer#bit_length,Integer.sqrtandModule#private_instance_methods. mruby 4.1 addsString#scrub. mruby’s lists of user-visible changes (doc/mruby3.4.md,doc/mruby4.0.md,NEWS.md) name more (#561, #678) Dir.childrenandDir#each_childlist the entries of a directory without.and.., as in CRuby, andDir.empty?tells whether a directory has no entries (#559, #561). ngx_mruby 2.x tookDirfrom iij/mruby-dir, which has none of the three methods.Dirnow comes from mruby’s core gem mruby-dir (see Class and Method), and with the bundled mruby the two methods leave out.and..(since mruby 3.4, mruby/mruby#6265). With mruby 3.3.0, which no release of ngx_mruby combined with mruby-dir, they were aliases ofDir.entriesandDir#eachand included.and..; the test suite of ngx_mruby saw the change (test/t/cases/gem_dir.rb). A script written for such a build that skipped.and..after these calls can drop that code, or keep usingDir.entries.Diralso includesEnumerable, which iij/mruby-dir does not, soDir.open(path) { |d| d.select { |name| name.end_with?(".txt") } }works;Dir.openwith a block closes theDirwhen the block ends.Process.clock_gettimeandProcess.clock_getreswithProcess::CLOCK_REALTIME,CLOCK_MONOTONIC,CLOCK_PROCESS_CPUTIME_IDandCLOCK_THREAD_CPUTIME_ID,Process.times(aProcess::Tms), andProcess.waitandProcess.wait2, from mruby’s core gem mruby-process, which replaces iij/mruby-process;Signal.listandSignal.signamefrom mruby-signal, which mruby-process depends on (#766)ENVincludesEnumerableand haseach,to_h,select,reject,slice,empty?,length,key,has_value?,assoc,rassoc,replaceandupdate, from mruby’s core gem mruby-env, which replaces iij/mruby-env (#766)mruby_variable $name [value];in thehttpblock declares a variable for scripts to assign withNginx::Var, without asetthat runs in the request. Asetat theserverlevel runs after the server rewrite handler and overwrites the value that the handler assigned;mruby_variableruns in no phase of the request. Until a script or asetassigns the variable in a request, it reads asvalue, which may contain variables, or as the empty string without one. nginx computesvaluewhen the request first reads the variable, not in a phase assetdoes, and keeps it for the request, which subrequests share: with"$request_time"asvalue, anaccess_logthat alone reads the variable writes the time of the whole request, and a server rewrite handler that reads it first fixes0.000for the rest of the request;"$upstream_addr"gives the upstream’s address to alog_format, wheresetassigns the empty string, because no upstream is chosen yet in the rewrite phase.nginx -trefuses a name that nginx or another module defines with a value of its own, such as$uri,$args,$http_NAMEor a variable ofmap; see mruby_variable (#780)Nginx::Request#storereturns a Hash that is the same object in every handler and filter of a request, so that a handler passes values to a later handler of the same request without an nginx variable. The first call creates it, empty. It stays after an internal redirect (error_page,try_files, a named location,Nginx.redirectwith a local URI) and until nginx frees the request, after the log handlers. A subrequest gets an empty store of its own. A request whose handlers do not call the method allocates nothing for it; see Nginx::Request (#832)#store
Dir.foreachwith a block closes theDirthat it opened. With iij/mruby-dir of 2.x, thatDirkept a file descriptor of the worker open until the GC freed it (#559)- When
mrb_open()fails while nginx reads the configuration, the http module logsngx_mruby: mrb_open() failedand the stream modulengx_mruby-stream-module: mrb_open() failedat theemerglevel, followed by: <class> raised while initializing mrubywhen the initialization of mruby or of a gem raised an exception. nginx stops as before; ngx_mruby 2.x logged no line of its own (#559) - A handler that calls
Nginx::Async.sleepseveral times keeps one timer and one cleanup in the request pool instead of one of each per call. An HTTP handler that never waits no longer stores its fiber in the GC root holder or adds a cleanup, and a stream handler that never sleeps no longer adds a cleanup; the fiber is stored at its first wait. The compiled code of a handler is prepared once, when it is compiled or loaded, instead of on every run.Nginx::Async.sleep,Nginx::Stream::Async.sleepandNginx::Async::HTTP.sub_requestadd their cleanup and check each allocation before they arm the timer or post the subrequest, so that a failed allocation raises aRuntimeErrorwith nothing armed (#714) - When a handler writes its response with
Nginx.rputsin a location withmruby_output_body_filterormruby_output_body_filter_code, and nginx cannot send the response in one write (for example withlimit_rateorsendfile_max_chunk, or to a client that reads slowly), nginx now sends the rest of the response, also when the handler set the status of the output before or after it. Before, the client received the header with the fullContent-Lengthand only the part of the body that the first write sent, and nginx closed the connection whensend_timeoutpassed (#784, #785) - In a build with
--with-debug, a script that redefinesbacktraceon an exception class so that it returns elements that are not Strings no longer makes the logging of the backtrace read those elements as Strings, which was undefined behavior: such an element is skipped, and the Strings of the backtrace are logged as before (#796) - When a script redefines
inspectorbacktraceof an exception class so that they raise, and the handler that raised the exception runs inside another mruby call (for example in the location thatNginx.redirectruns from anmruby_sethandler), the exception ofinspectorbacktracestops in the logging of the exception, as an exception of a resumed fiber stops inngx_mrb_fiber_resume. Before, it went to the outer mruby call past the nginx functions between the two calls: nginx did not finish the request, the client waited for the response until it gave up, anderror.loghad the exception ofinspectorbacktrace, logged by the outer call, instead of the exception of the handler. Abacktracethat raises is logged, in a build with--with-debug, as a backtrace that is not an Array (#799)
Build and test changes
Section titled “Build and test changes”-
Extend the UDP session tests with single-datagram controls around the multi-datagram case, consecutive sleeps, exact binary proxy payloads and bounded shutdown. CRuby helpers use the staged suite path, including when
TEST_SH_PORT_OFFSETmoves the ports. These tests cover the existing next implementation; no runtime code changes. -
Add normal TCP sleep coverage to the default soak and callgrind comparisons. The shared client requires exact bytes and EOF within a total deadline; the soak checks active and released stream counters and collects the stream VM before RSS samples. The callgrind window requires exactly one stream fiber start per measured session.
-
New regression case:
test/t/cases/head_body_filter.rbsends HEAD and then GET on one TCP connection, covering both output origins, an empty replacement and ordinary HEAD/GET controls. Its raw helper uses the suite path so the same cases run withTEST_SH_PORT_OFFSET. -
New test case:
test/t/cases/head_header_filter.rbsends HEAD, or a GET control, and then GET on one TCP connection, with the helper ofhead_body_filter.rb, to new locations of the server on port 18112: a header filter alone on a response ofreturnand on a static file, and a body filter on a listing ofautoindex, which has noContent-Length(#848). A location of the same server sends the listing at 50 bytes a second (limit_rate 50,send_timeout 3s), so that the header of the HEAD response needs more than one write (#856). -
New test case:
test/t/cases/header_only_keepalive.rbsends a GET that nginx answers with 304 (If-Modified-Sinceto a static file withif_modified_since before) or 204 (return 204;), through a header filter alone and through a body filter, and then GET on the same TCP connection, to new locations of the server on port 18112; one of them reads its file through an output buffer smaller than the file, withsend_timeout 3s, so that a body filter that keeps the dropped buffer of a 304 or HEAD response fails the case within seconds.test/t/cases/_head_filter_client.rbtakes request header lines as an optional third argument, and ends the first response at its header for 204 and 304 as for HEAD (#849). -
test/t/cases/async_sleep_many.rbchecks that one HTTP content handler sleeps 1,000 times for 1 ms, answers 200 withslept:1000, and restores thetimersandgc_root_fiberscounters. Its server uses port 18188 and each request has a 60-second limit.test.shenablesNginx::Debugfor these assertions; reconfigure an existing test build as described in “The integration test build enablesNginx::Debug” above before usingONLY_BUILD_NGX_MRUBY=1. The defaultbuild.shbuild is unchanged. -
The Markdown link check accepts explicit HTML anchors, so a renamed heading can retain its existing links.
-
The index pages of the site (
/,/ja/,/v2/,/v2/ja/) show a strip of development-practice badges below the hero, or below the page title on the 2.x pages: the workflowstest,nginx-tests(3.x pages only),valgrind-nightly, CodeQL and zizmor of the branch that the page describes, OpenSSF Best Practices and the MIT license. The status line of the home pages names the newest stable release with a badge that the build draws from the git tags, and the GitHub link of the header shows the repository’s star count, which the site workflow reads from the GitHub API before the build. The site checks verify the links, image URLs, sizes and alt text of the strip, the release badge and the star count, and in a browser at 1440px and 402px, in light and dark, the size and position of each badge, the keyboard order, and that the strip keeps its box when the external images fail. The checks before the deploy serve local stand-ins at the external badge URLs, so they never wait on GitHub or bestpractices.dev; the check after the deploy fetches the real images, with retries (#687, #718, #725). -
Pull requests to
nextdo not run the site workflowsite.yml. It runs on every push tonextand on a dispatch: it builds the site from a fresh clone and again with the network blocked, builds the 2.x pages frommaster, runs the checks that need no browser, publishes the site and checks the published site. The browser checks of the site run locally only:npm run check:ciinsite/runs the checks of the build job ofsite.ymland then every browser check on every page, in Chromium and WebKit, with Japanese text in the served Noto Sans JP, and the author of a pull request quotes it. When the base of a pull request moves, CI runs again only when both the pull request and the new commits of the base change the code or the tests (condition 2 of “Review and merge” in AGENTS.md; “Site CI” in docs/test/README.md) (#677, #737). -
The site workflow checks initial Copy controls and Japanese maintenance-entry line layout, and records desktop/mobile reader journeys. After a successful production deployment, read-only checks compare the same-run artifact and deployment SHA, verify the public branch policy and live HTML/HTTPS/Lighthouse, and retain a small set of actual public-page screenshots. A PR-only preview can inspect the stable-entry candidate; production always builds stable docs from master (#672).
-
After a deploy, the check of the published site (
site/scripts/screenshots-live.mjsin theverify-livejob ofsite.yml) no longer fails on the short burst of 503 answers that GitHub Pages gives right after a deploy. When the only errors of a browser context are 5xx answers of the site and failed requests of the same URLs, it fetches those URLs until they answer 200, at most 240 seconds in a run, and checks that context again, once; every other error still fails at once, and each retry is printed and recorded inevidence.json.site/scripts/test-screenshots-live.mjs, whichnpm run check:ciruns, checks the retry against a proxy that answers 503 or 404 (#836). -
The installation guide integrates the corrected 2.x build/install lifecycle from #660 while selecting the
nextdevelopment branch, retaining v3 core-gem and lock-file contracts. English/Japanese examples use the same commands; a fresh development build and loopback HTTP trial are recorded with their revision and limits. -
The site exports version-specific Markdown pages and a JSON documentation index from the same source as HTML, with language, source revision/hash and dirty-preview metadata. Full-body, source and fallback-link checks cover both release lines; display word breaks and SVG are omitted while literal code, tested sample bytes and diagram provenance remain. This does not make a development API stable or certify historical examples as current measurements.
-
The English and Japanese site home pages present the tested nginx configuration, Ruby handler and HTTP exchange together, with a homepage palette and responsive layout. The site checks cover its colors, text scale and shared code highlighting; the rebrand preview extends the navy/graphite surfaces and copper accents to documentation pages.
-
build_config.rb.lockrecords mruby 4.1.0 (version: 4.1.0,release_no: 40100, written by rake for 4.1.0-rc2, #678) and no longer has an entry for luisbebop/mruby-polarssl, which the test build no longer clones (#561) -
The lock pins matsumotory/mruby-uname, in the host and the test build, to
50031c81b101f44e89bf482f5c31213b6c07af36on the gem’smaster(branch: master): the merge commit of matsumotory/mruby-uname#1, which declares the instances ofUnameas data objects (MRB_SET_INSTANCE_TT(uname, MRB_TT_DATA)). Its tree is that of the fix commitc82f8a6, and a build no longer depends on the gem’s branchmruby-4(#561) -
The test client (the
testbuild ofbuild_config.rb) is built withNO_SSL(ENV['NO_SSL'] ||= '1'), because matsumotory/mruby-simplehttp depends on mruby-polarssl unlessNO_SSLis set, and luisbebop/mruby-polarssl depends on mruby-print.SimpleHttpandHttpRequestof the test client cannot sendhttpsrequests; the tests send HTTPS withcurl -kandopenssl s_client(docs/test/README.md). rake loads the gems of all builds in one process, soNO_SSLalso reaches a host build of your own that has mruby-simplehttp (#561) -
The default build makes 14 clones (8 in
mruby/build/repos/host, 6 inmruby/build/repos/test, about 8.5 MiB), and the build script of matsumotory/mruby-redis clones the hiredis tagv1.5.0intomruby/build/host/mrbgems/mruby-redis/hiredis-v1.5.0; luisbebop/mruby-polarssl with its submodule ARMmbed/mbedtls, mruby/mgem-list, iij/mruby-env, iij/mruby-process, matsumotory/mruby-vedis with symisc/vedis, matsumotory/mruby-localmemcache, iij/mruby-digest and monochromegane/mruby-secure-random are no longer cloned (#561, #606, #766, #771) -
build_config.rb.lockhas no entries for iij/mruby-env (host and test builds), iij/mruby-process, matsumotory/mruby-vedis and matsumotory/mruby-localmemcache, which the default build no longer takes (#766) -
build_config.rb.lockhas no entries for iij/mruby-digest and monochromegane/mruby-secure-random, which the default build no longer takes (#771) -
CI builds OpenSSL 3.5.9 in every cell of the
buildmatrix oftest.yml, in place of 1.1.1w: it installs it into/usr/local, and the cells with--with-openssl-srcbuild it into nginx as well.configurereads the version of an OpenSSL 3 source tree fromVERSION.dat, where it stopped withCan't find openssl version information, and the OpenSSL that ngx_mruby builds for--with-openssl-srcinstalls its libraries intolib; an OpenSSL 3 is built withbuild_sw, then installed withinstall_swwithout parallel jobs, because the two goals in one parallel make compiled the same objects twice at the same time. With--with-openssl-src,configuregives the mruby build the headers and the libraries of that OpenSSL (NGX_MRUBY_CFLAGSandNGX_MRUBY_LDFLAGS), so that the gems ofmrbgems/do not take those of the system; on macOS, it also looks for the OpenSSL of Homebrew under/opt/homebrew/opt/openssl(#771) -
New test case and the port of its server:
test/t/cases/gem_digest_secure_random.rb(Digest,Digest::HMACandSecureRandom, 18196) (#771) -
The default build includes matsumotory/mruby-redis again, as the default build of 2.7.2 does (“Redis is in the default build again” in the 2.7.2 notes, #604). The lock pins it, in the host build, to
8d939104923bc86bb16d2c203d91e22bfa3196dfon the gem’smaster(branch: master): the merge commit of matsumotory/mruby-redis#109, which keeps the connection ofRedis.connect_set_udptrin themrb_stateinstead ofmrb->ud(“Redis.connect_set_ udptr and Redis.new without arguments keep the connection in the mrb_state” in the 2.7.2 notes). From matsumotory/mruby-redis#108, the build of that commit clones the hiredis tag v1.5.0, checks its commit5bb7f030f6631b243438cf0fdd3be84352b905bband builds it withUSE_WERROR=0, and the gem declaresRedis#ttlwith one argument: mruby 4.0.0 checks the argument count of a C method against its declaration, and with the gem’s earlier declarationr.ttl "key"raisedArgumentError. The lock also pins matsumotory/mruby-pointer, which mruby-redis depends on and which adds no class, to8b46506dfdb12a79a16be1d1172ef3c9324bef96on itsmaster(#606) -
mruby/holds the tree of the mruby tag4.1.0-rc2(commitc17ffcc24190), merged as a subtree squash that recordsgit-subtree-split: c17ffcc24190b71682bc611fa80053bb252ad482, so the nextupdate-mruby-subtreemerges from that commit. docs/DEVELOPMENT.md describes how to finish anupdate-mruby-subtreethat stops with conflicts undermruby/: replace the subtree with the exact tree of the ref withgit read-tree, check thatgit write-tree --prefix=mruby/andgit rev-parse REF^{tree}print the same id, and commit the merge alone, with the build changes in the commits that follow (#561, #678) -
mruby/mrbgems/mruby-compiler/lib/prismholds 48 files of ruby/prism at the commitc0e37816e97ethat mruby 4.1.0-rc2 names for its submodule there:src/,include/,config.yml, the templates that the build renders withtemplates/template.rb, andLICENSE.md. A checkout or a source archive of ngx_mruby therefore builds without fetching the submodule. The new scriptvendor-mruby-prismwrites them after the merge commit of an mruby update and stops unless each file is the blob of that commit (docs/DEVELOPMENT.md, “Prism”). The build of mruby needs Ruby, which it needed before, to render the templates (#678) -
NGX_MRUBY_ALLOW_MISSING_CORE_GEMS=1in the environment of the mruby build skips, with a notice, the names inNGX_MRUBY_CORE_GEMSthat the mruby being built does not have, where the build would otherwise stop. It is meant for the time of an update of the bundled mruby (docs/DEVELOPMENT.md) (#559) -
The memory soak test:
sh test/soak/run.shbuilds ngx_mruby inbuild_soak/with-DNGX_MRUBY_DEBUG_STATS, which adds the classNginx::Debug(Nginx::Debug.gc, andNginx::Debug.statswith the GC registrations that ngx_mruby counts), and runs its scenarios against it. It listens on 12360 and 12361, and starts a mock LLM upstream on 12362 for the agent proxy scenarios. The default build of build.sh does not haveNginx::Debug; test.sh enables it for the integration suite. Thesoakjob of CI runs the test, and onnextthe required checkci-okneeds that job (“Soak test for memory” in docs/test/README.md) (#542, #554, #557) -
The performance comparison:
sh test/perf/compare.sh BASE_DIRbuilds the checkout inBASE_DIRand this checkout inbuild_perf/, and compares the instructions per request that callgrind counts in each scenario. It listens on 12370 and 12371, and starts the mock LLM upstream on 12372. Theperfjob of CI runs it for pull requests that change an input of the measured binary, the measurement or the workflow (“Performance comparison with callgrind” in docs/test/README.md) (#549, #554) -
The agent proxy tests:
test/t/cases/agent_proxy.rbsends requests to the agent proxy recipes oftest/conf/conf.d/60-agent-proxy.confon port 18132, with a mock LLM upstream (test/soak/mock_llm.rb) thattest/t/cases/_agent_proxy_client.rbstarts on 12372 and 12373 (“Mock LLM upstream” in docs/test/README.md) (#554) -
The mock LLM upstream
test/soak/mock_llm.rbalso answersPOST /v1/responsesas the OpenAI Responses API does, with and without a stream. A stream ends withresponse.completed,response.incompleteorresponse.failed, chosen with--terminalor the request headerx-mock-terminal. The perf lane measuresresponses_stream_plain_50in its default set andresponses_stream_plain_1000whenPERF_SCENARIOSnames it, the soak test runsagent_responses_stream, andtest/t/cases/agent_proxy.rbchecks its recipes on/v1/responsesas well. No port is added (“Mock LLM upstream” in docs/test/README.md) (#600) -
New test cases and the ports of their servers:
test/t/cases/gem_dir.rb(Dir, 18127) andtest/t/cases/gem_uname.rb(mruby-uname, 18128) (#559),test/t/cases/config_time_log.rb(the messages logged while nginx reads the configuration, 18140) (#565),test/t/cases/return_in_block.rb(areturninside a block or aforbody of handler code, 18117) (#584),test/t/cases/var_method_lookup.rb(the accessors ofNginx::Varand the methods that read variables, 18159) (#610),test/t/cases/home_example.rb(the example of the home page of the site, 18160) (#617), andtest/t/cases/guides.rb(the samples of the guides and use cases of the site, 18161 to 18168 and the stream port 12364) (#619), andtest/t/cases/gem_env_process.rb(ENV,Process,Signal,sleepandexitin a handler, and thatVedisandCacheare not defined, 18118) (#766) -
dependence/ngx_devel_kit/holds the tree of the ngx_devel_kit tag v0.3.4(commitbd44d1630), with the one change of ngx_mruby kept: insrc/ndk_set_var.c, anNGX_DONEthat the variable handler ofmruby_setreturns becomes the status of nginx’s script engine. The tree was merged withupdate-devkit-subtree v0.3.4as a subtree squash that recordsgit-subtree-split: bd44d16302273052d6005d7bdb55f74e23813de3, so the nextupdate-devkit-subtreemerges from that commit. The tree before was the tagv0.3.1(a22dade76), whosesrc/ndk.hsaid 0.2.15. ngx_mruby enables only theset_varpart of NDK (have=NDK_SET_VARinconfig.in). Of the files that such a build compiles, the commits since v0.3.1 change onlysrc/ndk.handsrc/ndk_string_util.h, in lines that produce no machine code: the version macros ofsrc/ndk.hare used nowhere, NDK’sconfigalways definesNDK, so the removed#errornever applied, andndk_memcpypis a macro whose only user,src/ndk_conf_file.c, is not compiled. The commits fix the argument thatndk_conf_set_http_complex_path_slotpasses to its post handler and the size thatndk_memcpypcopies, correct the type in the size of the bucket array thatndk_upstream_listallocates (the number of bytes stays the same), remove the#errorthatsrc/ndk.hraised in a build withoutNDK, and setNDK_VERSIONto “0.3.4”. A build that also adds a module which enables those parts of NDK compiles the fixed code (#597) -
nginx’s own test suite:
sh test/nginx-tests/run.shruns nginx-tests at a pinned commit withproveon nginx built with ngx_mruby bytest.shand on nginx of the same version and configure options without ngx_mruby, and writes the counts of both builds and the test files that fail on each tobuild_nginxtests/summary.md. It needs Linux, a user other than root and perl, and the test files listen on ports from 8000 to 8999.TEST_SH_SKIP_TESTS=1 sh test.shstops after the build and the install. Thenginx-testsworkflow of CI runs it on pull requests tonextthat change the nginx binary,test.shor the runner; the required checkci-okdoes not need it (“nginx’s own test suite (nginx-tests)” in docs/test/README.md) (#602) -
The memory soak test also checks
Nginx::Debugitself: in each scenario oftest/soak/nginx.confit requests the new location/debug/checkonce before the warmup, and the scenario fails unlessNginx::Debug.statshas the documented keys with Integer values,Nginx::Debug.gcreturnsnil, and the full GC ofNginx::Debug.gcfrees the objects that nothing references (“Soak test for memory” in docs/test/README.md) (#605) -
gc_rootandgc_root_fibersofNginx::Debug.statsin the soak build count the objects that ngx_mruby keeps from the GC: the holder of each mrb_state, which is registered withmrb_gc_register()once, and the fibers stored in it. ngx_mruby no longer callsmrb_gc_register()andmrb_gc_unregister()for each fiber of a handler; it stores the fiber in the holder and frees the slot when the fiber ends (“The soak build andNginx::Debug” in docs/test/README.md) (#682). In the stream module, each fiber of a session has its own slot and its own connection pool cleanup (ngx_stream_mrb_fiber_t), so that a second fiber of a UDP session, started by a second datagram while the first fiber sleeps, is kept from the GC as well, as 2.7.3 keeps it with a GC registration of its own (#698) -
The example of the start page of the site:
examples/start/holds acompose.yamland aDockerfilethat build nginx with ngx_mruby from the checkout, with annginx.confand a Ruby script, and itsREADME.mdis the page/start/. Theexamplesworkflow of CI runs the commands of that README in order withexamples/check_example.pyand compares their output with what the README states, on pull requests tonextthat changeexamples/, the workflow or the inputs of the build (src/,mrbgems/,mruby/,dependence/,build.sh,build_config.rb,build_config.rb.lock,nginx_version,configure,config.in,Makefile.in); the required checkci-okdoes not need it (#618) -
test/t/cases/agent_proxy.rbreads the values that it compares for the recipes of the Messages API fromtest/html/agent_proxy_auth.expected,agent_proxy_route.expected,agent_proxy_limit.expectedandagent_proxy_log.expected, onekey=valueper line, orkey~=textfor a value that contains the text, which the agent proxy page of the site shows;test/t/cases/_agent_proxy_client.rbtakes the port of nginx as an optional third argument (#622) -
test.shstops only the nginx that it started, by its pid. It no longer runskillall nginx(pkill nginxon NetBSD, FreeBSD and CentOS) before it starts the test nginx, which stopped every nginx on the machine. Before the start, it stops the nginx that an earlier run in the same build directory left running, by the pid inlogs/nginx.pid, when that process runs thesbin/nginxof this build. When it exits, also after a failure and on SIGHUP, SIGINT or SIGTERM (once the command that runs at that moment, such as the wait for nginx or the current test file, has ended), it sends SIGTERM to the test nginx and sends it again 1, 3, 7, 15 and 31 seconds later while the process still runs, because a single nginx process can miss a SIGTERM that arrives right before it waits for events; afterNGINX_STOPTIMEseconds (default 60) it sends SIGKILL and exits 1. Before each signal, it checks that the pid still runs thesbin/nginxof this build, so a pid that another process took after nginx ended gets no signal.test/t/cases/_second_instance.rbsends the SIGQUIT to its nginx again in the same way (“Stopping nginx” in docs/test/README.md) (#635) -
TEST_SH_PORT_OFFSET=N(an integer from -2345 to 47336, default 0) moves every port of the test suite by N, so that two checkouts can runtest.shat the same time on one machine, each with its own offset. The ports of the suite are the numbers from 12345 to 12399 and from 18080 to 18199 intest/t,test/conf,test/htmland the two files oftest/soakthat the agent proxy tests load.test.shcopies these files with the new scripttest/t/cases/_stage.rbtobuild/nginx/harness/test/, moving each such number written as five digits by N, and installs the configuration and the hook scripts and runs the tests from that copy; the tests run the CRuby helpers of the copy through the new methodsuite_pathoftest/t/cases/_prelude.rb. With offset 0 the copy is the same as the source._stage.rbfails for such a number written with an underscore and for an offset that would move a port out of 10000 to 65535 (“Ports” in docs/test/README.md) (#641) -
The message that
test.shprints when it sends SIGKILL to the test nginx appears only when it sent the signal: when the pid no longer runs this build’s nginx at that moment, the stop ends without the signal and counts as ended, sotest.shkeeps the exit status of the tests. Before, it printed that it sent SIGKILL, andtest.shexited 1; at the start, the stop of the nginx left by an earlier run ended the run (#641) -
valgrind fails the CI cell that runs nginx under it: such a cell runs nginx with
valgrind --error-exitcode=99 --leak-check=full --errors-for-leak-kinds=definite,indirectand the suppressions of the new filetest/valgrind.supp, and its step “Check the valgrind reports” fails the cell when theERROR SUMMARYof a valgrind log counts an error: a memory error, or a definitely or indirectly lost block that the file does not suppress. The file suppresses the environment array that nginx leaves allocated at exit (ngx_set_environment(), 8 bytes). Possibly lost blocks are printed but are not errors. In a run that starts thebuildmatrix, one cell (nginx 1.31.8, static module) runs nginx under valgrind, and the other cells without a sanitizer run it directly. A manual run oftest.ymlwith the new inputvalgrindruns every cell except the sanitizer cell under valgrind; the new workflowvalgrind-nightly.ymlstarts such a run every day from its copy onmaster, the default branch (#674).test.shstill does not take valgrind’s errors into its exit status (“valgrind in CI” in docs/test/README.md) (#634) -
The site is deployed: the job
deployof.github/workflows/site.ymlpublishes the site that the jobbuildbuilt and checked to GitHub Pages athttps://ngx.mruby.org/, on a push tonextand on aworkflow_dispatchonnext, never for a pull request. It usesactions/configure-pages,actions/upload-pages-artifactandactions/deploy-pages, pinned by commit, with the permissionspages: writeandid-token: writeonly, and stops unless the Pages settings give the originhttps://ngx.mruby.org. The site serves the Google verification filegoogleba3435e4002729b6.htmlof the old site at the same URL and loads no analytics script, whichsite/scripts/check-deploy.mjschecks on every run;site/scripts/check-live.mjschecks the live site after a deployment, by hand (“The site” in AGENTS.md) (#653) -
The site builds the documentation of 2.x under
/v2/fromdocs/ofmaster:node site/scripts/build-v2.mjs --tree DIR(npm run build:v2insite/), afternpm run build, writes the 2.x pages intosite/dist/v2/with a search index of their own, andsite/scripts/check-v2.mjschecks the 2.x banner on every 2.x page, the version links between/v2/and/docs/, and that the search of each version shows only its own pages. Thesiteworkflow checks outmasterand builds/v2/on every run. Thesite-v2workflow runs on “Run workflow” to build and check the 2.x pages of the selected branch, and thesite-dispatchworkflow starts thesiteworkflow onnextafter every push tomaster(#657, #656) -
CI runs only the jobs that a change needs. The new script
test/ci/changes.shsorts the files of a change (a renamed file with its old and its new path) into the categoriescode,tests,docs,site,examplesandworkflows, a file of no category counting ascode, and the workflows read it. In a ready pull request, a change of the code runs four cells of thebuildmatrix oftest.yml(the entry of #702 below),soakandperf; a change oftest/,test.shortest.ymlalone runs the same four cells, andsoakor the comparison ofperfonly when their own files changed; any other change runs none of them, and the jobchangesoftest.ymldecides. A draft pull request runs no CI:test.ymlnames its jobci-ok (draft)instead of the requiredci-ok, the other workflows skip their jobs, and marking the pull request ready for review starts the run. A push tomasterornextruns no build or test job, only the deploy of the site and the scans of CodeQL;nginx-tests,examplesandzizmorrun on pull requests only. A push of a tag and “Run workflow” run the whole matrix andsoak(perfruns on pull requests only), and “Run workflow” with the new inputbasedecides as for a pull request against that branch, with the resultci-ok (dry run); any other “Run workflow” reportsci-ok (manual), so that only the run of a pull request or a push gives the requiredci-ok.ci-okcounts a skipped job as passed only whenchangesdecided to skip it. The run of every cell under valgrind is nightly only:valgrind-nightly.ymlno longer runs on pull requests, its run names the jobci-ok (valgrind), and it reads the result of the run with retries, so that a failed call of the API does not fail the job. The new workflowcodeql.ymlruns CodeQL for C and C++ (without a build), Ruby and the workflows on ready pull requests and pushes tomasterandnextthat changesrc/,mrbgems/or.github/workflows/, and weekly, in place of GitHub’s default setup (“Which jobs a run starts” and “CodeQL” in docs/test/README.md) (#676, #685, #686) -
CI: a cancelled run reports no result for
ci-ok, where it reported a failure. CodeQL leaves out the vendored treesmruby/anddependence/(.github/codeql/codeql-config.yml), and the alerts on them were dismissed as vendored upstream code. AGENTS.md and docs/test/README.md say that CI is the final check in a clean environment and that the author runs the checks that a change touches locally before the pull request is marked ready (#692) -
The performance comparison applies the accepted differences of the new file
test/perf/accepted.txt. A line names a condition (mruby-version: theMAJOR.MINORof the bundled mruby in the base and in the head), a scenario, and an allowance on the change of Ir per request without GC, in percent. When both builds match a line, aWARNorFAILrow of its scenario within the allowance shows asok (accepted: ...)and does not fail the run; a change above the allowance keeps itsWARNorFAIL. The first line acceptsauthup to +8% from mruby 4.0 to 4.1, the difference accepted on #678, so that a comparison with a base onnextfrom before #678 does not report it asFAIL. No line covers mruby 3.3 (2.7.2) against 4.1. The report prints the mruby version of both builds and the accepted differences that applied, andPERF_ACCEPTED_FILEnames another file (“Known differences” in docs/test/README.md) (#696) -
CI: a ready pull request that changes the code or the tests runs four cells of the
buildmatrix oftest.yml, not every cell (the 8 combinations of nginx version, link mode and--with-openssl-src, and the sanitizer cell). The four cells are nginx 1.31.8 with the static module and--with-openssl-src, nginx 1.30.6 with the dynamic module, the sanitizer cell (AddressSanitizer and UndefinedBehaviorSanitizer) and the cell under valgrind; the last two build nginx 1.31.8 with the static module. Every cell, andsoak, runs in the nightly run under valgrind, on the push of a tag, on a pull request with the new labelfull-matrix(the check pull request before a tag), and on “Run workflow” without the inputbaseor with the inputvalgrind. A push to av*.xbranch runs no build, as a push tomasterornextdoes not.test/ci/changes.shtakes the run as options (--label,--draft,--push,--tag,--dispatch,--valgrind) and givesbuildstandard,fullornone(“Which jobs a run starts” in docs/test/README.md) (#702) -
The test suite runs nginx with a master process and several worker processes, and reloads it.
test/t/cases/workers.rbruns the CRuby helpertest/t/cases/_workers.rbthrough the prelude helperworkers_nginx. The helper starts nginx withmaster_process onfrom a configuration oftest/conf/workers/, with four workers on port 18180 or two workers on 18181 and the stream port 12379, sends requests that reach every worker, reloads nginx with SIGHUP while anNginx::Async.sleepand anNginx::Stream::Async.sleepare in flight, and stops the master and every worker, the master by the pid of its pid file. The case asserts that each worker answers from an mrb_state of its own that its requests share; that after the reload the new configuration and script answer while the old workers finish the two sleeps and then end; and that the error log has no line at the levelerroror above, no sanitizer report and, under valgrind, no error in the report of any process. The test nginx oftest.shstays a single process (“Several workers and reloads” in docs/test/README.md).test/valgrind.suppsuppresses the connection and event arrays that nginx allocates inngx_event_process_init()of a worker process and never frees, which valgrind reports as lost when such a worker ends on SIGTERM on x86-64 (#706) -
Nginx::Debug.statsof the soak build hasstream_timers(theNginx::Stream::Async.sleeptimers that are pending) andstream_fibers(the stream fibers kept in the GC root holder), next totimersof the http module (#714) -
The merge of the 2.x changes adds the regression cases of
test/t/cases/async_rewrite_declined.rband its server on port 18187 (#740). The existing v3 handler implementation already preserves the status after a resumed decline.site-v2.ymlnow runs only on “Run workflow”; authors check the 2.x pages locally before a PR is ready, and a push tomasterstill starts the site build onnext(#739). -
New test case:
test/t/cases/output_value_to_s.rb, with the server oftest/conf/conf.d/88-output-value-to-s.confon port 18191 (#776) -
New test case:
test/t/cases/mruby_variable.rb, with the server oftest/conf/conf.d/89-mruby-variable.confon port 18171 (#780) -
New test case:
test/t/cases/request_store.rb, with the server oftest/conf/conf.d/99-request-store.confon port 18094 (#832) -
New test case:
test/t/cases/var_assign.rb, with the server oftest/conf/conf.d/99-var-assign.confon port 18107: the assignments ofNginx::Var#<name>=,Nginx::Var#setandmruby_setgive a variable the same value, and an assignment that nginx cannot take raises (#854) -
New test cases:
test/t/cases/body_filter_split_write.rb, with the server oftest/conf/conf.d/89-body-filter-split-write.confon port 18141, from the merge of the 2.x changes (#784), andtest/t/cases/body_filter_split_write_status.rb, with the server oftest/conf/conf.d/90-body-filter-split-write-status.confon port 18142, for output sent with a status that the handler set before or after it (#785) -
CI builds and tests nginx 1.31.8 and 1.30.6 only: the full
buildmatrix oftest.yml, which the nightly run, the push of a tag, the check pull request before a tag and “Run workflow” without the inputbaseuse, no longer has the cells of nginx 1.28.3 and 1.26.3, and has 8 combinations of the nginx version, the module type and--with-openssl-src, and the sanitizer cell (#789) -
CI: on
next, the required checkci-okoftest.ymlneeds theperfjob, so aFAILorERRORrow of the performance comparison fails it, and aWARNrow does not.test/perf/accepted.txthas a second condition,pull-request: its line names the base branch and the number of a pull request (for examplepull-request next 812 stream_sleep 7) and applies only in theperfjob of that pull request, which passes both toperf.rbinPERF_BASE_REFandPERF_PULL_REQUEST. A pull request adds such a line after the owner has accepted itsFAILin a comment, and the run passes. The comparison judges the Ir per request without the GC and without the constant lookups that miss the constant cache of mruby (w/o GC/const), whose misses depend on where the ireps were allocated and differed between two runs of the same commits on #766. A scenario whose head clears that cache more often than its base (mrb_const_set,mrb_const_remove,mrb_define_const_id,include,prepend,extend), or clears it and misses more lookups than its base, is judged with the lookups counted (w/o GC), and the columnjudgedof the report says which number judged each row. The report prints the misses and the clears per request (const_misses,const_clears) for both builds, and notes a scenario where the Ir of the difference of misses makes half of theWARNthreshold or more of the basew/o GC/const(“What it measures” and “In CI” under “Performance comparison with callgrind” in docs/test/README.md) (#794, #795) -
New test case:
test/t/cases/exception_log.rbchecks the level and the text of theerror.logline of an exception of a content handler (port 18192), of an SSL handshake handler (port 18193), of a stream session (port 12380), ofmruby_init_codeand ofmruby_stream_server_context_codeundernginx -t, the backtrace of a stream session in the debug build oftest.sh, and the lines for a redefinedbacktracethat returns elements that are not Strings or no Array.test/t/cases/log_negative_level.rbchecks the line ofNginx.log(port 18194) and ofNginx::Stream.log(port 12381) for a negative level. The exit hooks of the nginx oftest/t/cases/config_hooks.rbraise after their lines, and a case there checks the line of each exception (#796) -
New test case:
test/t/cases/exception_log_raising_methods.rbchecks the line of an exception whoseinspectorbacktraceraises, in a content handler (port 18198), in a stream session (port 12382) and in the location thatNginx.redirectruns from anmruby_sethandler, and that the worker answers the next request (#799) -
The test nginx of
test.sh(test/conf/nginx.conf) hasworker_connections 1024instead of 200. nginx counts each of its 125 listening sockets as a connection, and under valgrind the connections thattest.shopens to every port before the cases used up the rest, so nginx closed the connection of the first request of the suite (#818) -
New test case:
test/t/cases/code_reload.rb, with the server oftest/conf/conf.d/98-code-reload.confon port 18125, sends two requests to a content handler file withoutcachethat sleeps, the second while the first waits, so that the second compiles the code again meanwhile, and checks that both answer with the values of their code and thatgc_rootofNginx::Debug.statsis the same afterwards.gc_rootnow also counts the compiled code of each directive, which the GC root holder keeps for the life of themrb_state(“The soak build andNginx::Debug” in docs/test/README.md) (#825) -
New test case:
test/t/cases/stream_duplicate_hooks.rbrunsnginx -ton stream configurations that give a hook twice in one context, with a server on port 12398, whichnginx -topens for a moment when it accepts the configuration. The directives with Ruby code of the http and the stream module are rows of a table in their module header,NGX_HTTP_MRUBY_CODE_TABLEandNGX_STREAM_MRUBY_CODE_TABLE: a new directive of such a kind is a row there (“Adding a directive with Ruby code” in docs/DEVELOPMENT.md) (#834). -
New test case:
test/t/cases/filter_inherit.rbchecks that output filters given atserverlevel and in a location run in the locations andifblocks below them, with a server on port 18108, and, with the new modehttp_filterof the second nginx oftest/t/cases/_second_instance.rb(port 18116), a filter in thehttp {}block and the phase handlers that onlymruby_add_handler onor one form of a log handler uses (#835). -
New test case:
test/t/cases/filter_sendfile.rbchecks, with the new modehttp_sendfileof the second nginx oftest/t/cases/_second_instance.rb(port 18116), which hassendfile onand an error log of its own at the debug level, that nginx sends a static file withsendfileand does not read it into memory in a location with an mruby header filter alone, and reads it into memory in a location with an mruby body filter (#847).
Upgrading
Section titled “Upgrading”- Rebuild the soak and performance binaries without
ONLY_RUNto include stream support. Account for the newsessions,stream_timersandstream_fiberssoak columns and the session unit of thestream_sleepperformance row. - For an existing
test.shbuild, remove the selected nginx source tree’sobjs/Makefileand run the full suite withoutONLY_BUILD_NGX_MRUBY, preservingBUILD_DYNAMIC_MODULE=1for a dynamic module. Fresh test builds and productionbuild.shbuilds need no step for the debug counters.
Supported nginx versions: nginx 1.30 (stable) and 1.31 (mainline), raised
every April (see README.md). Read the release notes of the 2.x releases
newer than the version you run first, then this file. Rebuild the module
together with the bundled mruby 4.1.0-rc2; a build_config.rb of your own
needs the changes of “A build_config.rb of your own needs the core gem
changes of mruby 4.1”.
Migrating from ngx_mruby 2.x to 3.0.0 has the
steps for finding the scripts and builds that each entry affects. Check
these before upgrading:
-
The bundled mruby 4.1.0-rc2: rebuild the module together with it, and check mruby’s lists for the changes that these entries do not cover (#561, #678).
-
A
build_config.rbof your own: remove mruby-print, hal-posix-io, hal-posix-dir and hal-posix-socket, decide on mruby-task and mruby-encoding, and withfull-core.gemboxchoose between the core gems mruby-env, mruby-process and mruby-regexp and the third-party gems of the same classes (#561, #678). -
Ruby: build with Ruby 3.0 or later (#678).
-
nginx: build with nginx 1.30 or 1.31; to keep nginx 1.28 or 1.26, stay on 2.x, which builds with nginx 1.24 only without
--with-stream(#789). -
build_config.rb.lock: nothing for a new checkout or a source archive; to build a gem at another commit, change its entry, and removemruby/buildafter a change of the lock (#558). -
Hash#inspectandHash#to_s: do not use them as a data format; build the string yourself, or useJSON.generate(#561). -
Exception#inspect: update log parsers and alerts that match the old form of themrb_run failedlines (#561). -
"#@ivar","#@@cvar"and"#$global": escape the#of such strings that are meant literally, or use single quotes (#678). -
Syntax errors: match on
SyntaxErrorand the file and line, not on the text of the message (#678). -
An
Array, aHashor aStructthat holds itself: nothing, unless a script relies on theSystemStackErrorof the comparison (#678). -
The messages logged while nginx reads the configuration: to see them, run
nginx -t -e stderr, read the startup log afternginx -t, or reload witherror_logatinfo(#565). -
Nginx.module_versionand themechanism enabledline: where a script or a monitor compares the value with a 2.x version, compare it with3.0.0as well; use the tag or the commit of the build to tell the pre-releases of 3.0.0 apart (#823). -
NoMethodError: match on the exception class, not on the message (#561). -
privateandprotected: call such methods without a receiver, or withsend; list private methods withprivate_instance_methodsorprivate_methods(#561, #678). -
Module#remove_const,#private,#public,#protected,#module_functionand the hooks: call them in the body of the class or module without a receiver, or withsend(#561). -
Overrides of
append_features,prepend_featuresandextend_object: move the code toincluded,prependedorextended(#561). -
allbits?,anybits?andnobits?on a Float: convert withto_ifirst (#561). -
FileTest: nothing for calls of its methods (#561). -
A constant assigned in a method body: use
Object.const_set(orKernel.const_set) (#561). -
Bit operations on a Float: convert with
to_ifirst, or compute the old number as the entry says (#561). -
String#valid_encoding?: drop the call, or build with mruby-encoding and check the scripts (#561). -
A seeded
Randomorsrand: do not depend on its numbers across versions (#561). -
Set#inspect,Set#to_sandSet#flatten_merge: do not use the first two as a data format; calls.merge(Set.new(t).flatten)in place ofs.flatten_merge(t)(#561). -
Hash#default_proc=: pass a Proc ornil(#561). -
yieldwith keyword arguments: nothing (#561). -
A
returninside a block or aforbody of handler code: nothing (#561). -
A content handler that ends without output: a handler that relied on the 500 sets the status it means, for example
Nginx::HTTP_INTERNAL_SERVER_ERROR; log monitoring that matchesresponse body is empty. return NGX_HTTP_INTERNAL_SERVER_ERRORno longer sees such handlers of the main request with no status or a status from 200 to 299 that nginx does not answer by itself (#574). -
An output body filter that ends with an empty body: nothing (#574).
-
The accessors of
Nginx::Var: usev.exist?(name)to tell whether a variable exists, and give the methods of your scripts names that are not names of nginx variables (#610). -
Nginx::Connection,Nginx::ServerandNginx::Request: to return other values, define the methods on those classes; read variables withNginx::Varinstead of@iv_var(#610). -
Dir: rescueIOErrorinstead ofRuntimeErroraround aDirthat can be closed; a script for both versions rescues both (#559). -
ENV: callENV.to_hin place ofENV.to_hash(#766). -
Process: start other processes outside nginx instead offorkandsystem, or run a command withIO.popen; callProcess::Status#to_iin place ofto_int; keep the pid and the status in variables of your own instead ofProcess::Status.new(#766). -
exitin a handler: remove it; to answer with a status, callNginx.returnand let the code run to its end (#766). -
sleepwithout an argument: give the seconds, or useNginx::Async.sleep(#766). -
VedisandCache: keep the data in Redis or a store of your own, or uncomment the gem’s line inbuild_config.rb(#766). -
DigestandSecureRandom: build with OpenSSL 3.0 or later; callurlsafe_base64withoutnwhere a script relied on 22 characters, andnewwhere it relied ondupof a digest starting empty; remove a line of iij/mruby-digest or monochromegane/mruby-secure-random from abuild_config.rbof your own (#771). -
C extensions: declare classes that wrap C data with
MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA), define C methods with the spec thatmrb_get_argsreads, usemruby/io.h,mrb_temp_alloc()andMRB_OPEN_FAILURE(), callmrb_open()ormrb_open_core()without an allocator and definemrb_basic_alloc_func()for a custom one, and addmruby/build/host/includeto the include path, also in a list given with--with-mruby-incdir(#561, #572). -
The classes that came with the auto-ssl mrbgem: use
pack('m0')andunpack1('m')in place ofBase64,ENV['TMPDIR'] || '/tmp'in place ofDir.tmpdirandDir.mkdirin place ofDir.mktmpdir, or add the gems to abuild_config.rbof your own (#556). -
The auto-ssl mrbgem: get certificates with ngx_
http_ acme_ module, or keep a 2.x build for a server that needs Nginx::SSL::ACME; removeNGX_MRUBY_AUTO_SSLfrom the build environment (#640). -
Nginx::Upstream#server=andNginx::Stream::Connection#upstream_server=: rescueArgumentErrorfor a string that cannot be a server; a script for both versions rescuesArgumentErrorandRuntimeError, orStandardError(#680). -
Nginx::Upstream#server=with a host name: give an IP address that the script has without waiting, with an IPv4 address as four decimal numbers, or write the name in theserverline of theupstream {}block and do not call the setter; for a name with more than one address,Nginx::Upstream.newraises for that upstream, so remove that call too (#680). -
An access or post_read handler that waits in
Nginx::Async.sleep: an access handler that should deny the request after the sleep returnsNginx::HTTP_FORBIDDENorNginx::HTTP_UNAUTHORIZED(#715). -
An access or post_read handler that writes output: nothing (#715).
-
A handler that sets no result after an earlier handler returned a value for every request: a content handler or an access handler under
satisfy anythat should go on returnsNginx::DECLINEDitself (#715). -
An
mruby_sethandler that waits inNginx::Async.sleep: code that ended the request with a status after the sleep returns that status from a later handler (#715). -
A rewrite or server rewrite handler that ends without a result: a handler that should end the request returns the status it means (#720).
-
Nginx::Async::HTTP.sub_requestin a content handler afterNginx::Async.sleep: remove arescueof itsRuntimeError(#722). -
A handler that waits for
Nginx::Async::HTTP.sub_request: do the work that counted on the code running again after the call (#722). -
A UDP stream session whose code sleeps: code that counted on running once for each datagram does not sleep (#727).
-
A stream session that waits when
worker_shutdown_timeoutexpires: keep the sleeps that must finish shorter than the timeout (#727). -
Nginx::Stream::Connection.proxy_protocol_addrandproxy_protocol_ip: nothing for code that compares the result with a String; code that calls a String method on the result handlesnil, for example withto_s. -
The reads of a stream session on a listen with
proxy_protocolduringNginx::Stream::Async.sleep: nothing. -
Nginx.rputs,Nginx.echo,Nginx.redirect,Nginx::Filter#body=andNginx::Filter#outputwith an argument whoseto_sdoes not return a String: pass a String,nilor a value whoseto_sreturns a String (#776). -
Nginx.redirectwith a local URI: write nothing after the call that is meant for the client, and move code that read what the target set to the target (#728). -
Nginx::Async::HTTP.sub_requestinmruby_setandmruby_set_code: call it in a rewrite or access handler and set the variable there withNginx::Var#set(#735). -
An
mruby_setvalue that cannot be converted to a String: return a String from the code (#735). -
access_logand mruby log handlers: nothing for most configurations; to log the value that a variable had before the log handler, copy it into another variable withset(#770). -
Nginx.redirectwith a local URI in a log handler: call it in a rewrite, access or content handler instead (#770). -
Output and a status: a handler that relied on nginx’s page for the status, or on the
error_pageof the location, sets the status without output; one that sets 301, 302, 303, 307 or 308 with output setsLocationitself (#779); one that sets a status before its output and means to send the output with 200 callsNginx.return Nginx::HTTP_OKafter the output (#783). -
Methods that have no effect in a handler: remove the calls that now raise, or move them to a handler where they work, as the table of the entry and “Where the methods work” in
docs/class_and_method/README.mdsay; in a log handler, pass values toaccess_logthroughNginx::Var(#826). -
Nginx.redirectwith a local URI inmruby_setandmruby_set_codehandlers and in output filters: call it in a rewrite or access handler instead (#833). -
An assignment with
Nginx::Var#<name>=orNginx::Var#setto a variable that nginx does not know, does not let scripts change or keeps no value of: declare the variable withsetormruby_variable, do not assign variables such as$urior$http_host, rescueNameErrorandRuntimeErrorwhere the handler should go on, and match themrb_run failedline in log monitoring (#854). -
A stream hook given twice in one context: keep one directive of each hook in a context, the later one, which ran on 2.x, and remove the others (#834).
-
Output filters given at
httporserverlevel, or in a location with nested locations orifblocks: check that each can run for every response of the levels below it, and move a filter that should run in some locations only into those locations (#835). -
A location with an mruby header filter and no body filter: nothing; nginx no longer reads the files of its responses into memory, and the responses are the same (#847).
-
HEAD responses with an mruby output body filter: nothing. To close a connection deliberately, configure nginx’s keep-alive policy rather than relying on this filter error.
-
HEAD responses through an mruby header filter alone, or through an mruby body filter without
Content-Length: nothing; to close a connection deliberately, configure nginx’s keep-alive policy (#848). -
204 and 304 responses through an mruby output header or body filter: nothing; to close a connection deliberately, configure nginx’s keep-alive policy (#849).