matsumotory / ngx_mruby

ngx_mruby - A Fast and Memory-Efficient Web Server Extension Mechanism Using Scripting Language mruby for nginx
https://ngx.mruby.org/
988 stars 112 forks source link

return statement in do ... end block and for loops causes LocalJumpError #502

Open a2ikm opened 1 year ago

a2ikm commented 1 year ago

For example, the following locations cause LocalJumpError at their return statements and return 500 Internal Server Error.

location /enable_return_from_block {
    mruby_rewrite_handler_code '
      [0].each do |_|
        r = Nginx::Request.new
        r.headers_out["Location"] = "http://example.com"
        Nginx.return Nginx::HTTP_MOVED_TEMPORARILY
        return
      end
    ';
}

location /enable_return_from_for_statement {
    mruby_rewrite_handler_code '
      for _ in [0]
        r = Nginx::Request.new
        r.headers_out["Location"] = "http://example.com"
        Nginx.return Nginx::HTTP_MOVED_TEMPORARILY
        return
      end
    ';
}

Please check my test results, too: https://github.com/a2ikm/ngx_mruby/pull/2