ngx_mruby v2.7.7
Behavior changes: read before upgrading
Section titled “Behavior changes: read before upgrading”The line of error.log for an exception whose class redefines inspect or backtrace (#803)
Section titled “The line of error.log for an exception whose class redefines inspect or backtrace (#803)”- Before: when Ruby code raised an exception whose class redefines
inspectin Ruby, ngx_mruby wrote no line for the exception toerror.log, whatever the redefined method did. ngx_mruby called the method while the exception was still pending in the mruby state. In that state the bundled mruby does not run the method to its end: it goes on with the pending exception, so neither the String that the method would return nor an exception of the method itself reached ngx_mruby. In a build with--with-debug, abacktraceredefined in Ruby went the same way, and ngx_mruby wrotebacktrace must be Array. mrb_type=18at the debug level and no frame. In the content handler of a location thatNginx.redirectran from anmruby_sethandler, this left the request unfinished, whatever the redefinedinspectdid, or in a build with--with-debugthe redefinedbacktrace, also when it returned a String or an Array: the pending exception went on to themruby_sethandler, past the nginx functions in between. Themruby_sethandler logged that exception again, which for a redefinedinspectagain wrote no line of the exception, and for a redefinedbacktracewrote the line of the exception a second time and no frame. nginx then answered 404 from the static files of the target location instead of 500, and the connection stayed open until the client gave up. - Now: ngx_mruby calls
inspectandbacktracewith the pending exception set aside, and stops an exception that they raise in the logging. Wheninspectreturns a String, the line has that String, as for an exception whose class does not redefine it. Wheninspectraises, the line has#<Class> (inspect raised Class), with the class of the exception and the class of the exception ofinspect; when it returns another value, the line has#<Class> (inspect did not return a String). In a build with--with-debug, the String elements of the result of a redefinedbacktraceare logged, one line each, and its other elements are skipped; abacktracethat raises or does not return an Array is logged at the debug level as before. Inside another mruby call, the request ends with 500 as it does directly under nginx, and the worker goes on to the next request. - Why it changed:
- The defect:
inspectandbacktracewere called while the exception was pending, so a method written in Ruby never gave its result. Inside another mruby call, the pending exception left the logging and the request unfinished, whatever the method did. The same calls are fixed onnextby #796 and #799; this pull request brings the fix to 2.x. - Why the old behavior could not be kept: when an exception leaves the logging and jumps past the nginx functions that handle the request, the request and its connection stay open. When no line of the exception is written, the operator cannot learn from the log that the error happened. The class name in place of an
inspectthat cannot give a String is the line that 3.x writes for the same exception, so 2.x and 3.x write the same line. - What the documentation promised: the documentation said nothing about exceptions whose class redefines
inspectorbacktrace.
- The defect:
- Affected: scripts of every kind of handler (HTTP and stream, and the code that runs when nginx reads the configuration or a worker starts or exits) that raise an exception whose class redefines
inspectorbacktracein Ruby. An exception whose class does not redefine them gets the same line as before, byte for byte. - What to do: nothing, unless you parse
error.logfor these exceptions: the line now exists, with the text of the redefinedinspector the class name.
A non-String argument to a Request setter, Nginx::Async::HTTP.sub_request or Nginx::Headers_in/out#[]=
Section titled “A non-String argument to a Request setter, Nginx::Async::HTTP.sub_request or Nginx::Headers_in/out#[]=”Security advisory: GHSA-cjxv-4q9m-62pf.
- Before:
Nginx::Request#uri=,#args=,#method=,#protocol=,#request_line=,#unparsed_uri=and#content_type=(which share one macro),Nginx::Async::HTTP.sub_request(the request path), andNginx::Headers_in#[]=andNginx::Headers_out#[]=(the header name, and each value) did not check that the argument was a String, and read a non-String argument as if it were a String. - Now: these methods raise
TypeErrorfor a non-String argument, asNginx.rputs,Nginx.echo,Nginx.redirect,Nginx::Filter#body=and theNginx::Varsetter already do (#775). Anilargument keeps its meaning: a setter leaves the member unchanged and returns, andHeaders#[]=removes the header. - Why it changed:
- The defect: these methods read their argument as a String without checking its type. The advisory linked above has the details.
- Why the old behavior could not be kept: a value that is not a String has no string content, so reading it as a String has no defined result.
- What the documentation promised: the documentation of these methods describes a String argument.
- Affected: scripts that pass to one of these methods a value that may not be a String. A script that passes only a String (a literal, an interpolated string, or a value it has converted) is not affected.
- What to do: where a script may pass a non-String to one of these methods, convert it (for example with
.to_s) or handle theTypeError.
New features
Section titled “New features”None.
- When the class of an exception redefines
inspect(or, in a build with--with-debug,backtrace) in Ruby and the exception is raised in the content handler of a location thatNginx.redirectruns from anmruby_sethandler, nginx now finishes the request with 500, whatever the method does. Before, the exception went on to themruby_sethandler, nginx answered 404, and the connection stayed open until the client gave up (#803) - In a build with
--with-debug, an element of the result of a redefinedbacktracethat is not a String is skipped, as on 3.x. Before, the code read every element as a String without checking its type (#803) Nginx::Upstream#server=and the streamNginx::Stream::Connection#upstream_server=reset their per-peer store when the nginx cycle pool is freed, so a later cycle after a reload inmaster_process offdoes not reuse the store of an earlier cycle (GHSA-pmjr-f94r-j47g)
Build and test changes
Section titled “Build and test changes”- New test case:
test/t/cases/exception_log_script_methods.rb, with the server oftest/conf/conf.d/94-exception-log-script-methods.confon port 18091 and the stream servers oftest/conf/conf.d/stream/52-exception-log-script-methods.confon ports 12383 and 12389 (#803) - New test case:
test/t/cases/type_unchecked_reads.rb, with the server oftest/conf/conf.d/95-type-unchecked-reads.confon port 18192
Upgrading
Section titled “Upgrading”- No directive was added, renamed or removed. Rebuild the module with this release the way you built 2.7.6, and replace the binary or the dynamic module as usual.
Check these before upgrading. Each line is the “What to do” of its entry above.
- Tools that parse
error.logfor exceptions whose class redefinesinspectorbacktrace: the line of such an exception now exists, with the text of the redefinedinspector the class name. - Scripts that pass a value that may not be a String to a Request setter,
Nginx::Async::HTTP.sub_requestorNginx::Headers_in/out#[]=: convert it (for example with.to_s) or handle theTypeErrorthat these methods now raise for a non-String.