Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mruby_enable_read_request_body, mruby_set_code and mruby_content_handler_code don't work together #321

Open
yyamano opened this issue Nov 16, 2017 · 1 comment

Comments

@yyamano
Copy link
Collaborator

yyamano commented Nov 16, 2017

I get a SIGSEGV with the following configuration.

        location /read-request-in-mruby_set {
          mruby_enable_read_request_body on;
          mruby_set_code $body '
             req = Nginx::Request.new
             rc = req.read_body
             Nginx.log Nginx::LOG_ERR, "rc:#{rc}"
             body = req.get_body
             Nginx.log Nginx::LOG_ERR, "body:#{body}"
             body
          ';
          mruby_content_handler_code '
             Nginx.rputs "OK"
          ';
        }
Program received signal SIGSEGV, Segmentation fault.
0x0000000000553546 in ngx_mrb_rputs_inner (mrb=0xbecf90, self=..., with_lf=0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_core.c:154
154	  if (ctx->rputs_chain == NULL) {
Missing separate debuginfos, use: debuginfo-install glibc-2.17-106.el7_2.6.x86_64 nss-softokn-freebl-3.16.2.3-13.el7_1.x86_64 openssl-libs-1.0.1e-51.el7_2.5.x86_64 pcre-8.32-15.el7_2.1.x86_64 zlib-1.2.7-15.el7.x86_64
(gdb) bt
#0  0x0000000000553546 in ngx_mrb_rputs_inner (mrb=0xbecf90, self=..., with_lf=0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_core.c:154
#1  0x000000000055383c in ngx_mrb_rputs (mrb=0xbecf90, self=...) at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_core.c:201
#2  0x000000000058534c in mrb_vm_exec (mrb=mrb@entry=0xbecf90, proc=proc@entry=0xc3e1a8, pc=0xd35468)
    at /home/vagrant/ngx_mruby/mruby/src/vm.c:1414
#3  0x00000000005890f9 in mrb_vm_run (mrb=0xbecf90, proc=0xc3e1a8, self=..., stack_keep=<optimized out>)
    at /home/vagrant/ngx_mruby/mruby/src/vm.c:897
#4  0x000000000058b0ae in mrb_run (mrb=<optimized out>, proc=<optimized out>, self=...)
    at /home/vagrant/ngx_mruby/mruby/src/vm.c:2907
#5  0x000000000054e630 in ngx_mrb_run (r=0xbeb5b0, state=0xbe6328, code=0xd451d8, cached=1, result=0x0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_module.c:836
#6  0x0000000000550e46 in ngx_http_mruby_content_inline_handler (r=0xbeb5b0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_module.c:1577
#7  0x00000000004aeec4 in ngx_http_core_content_phase (r=0xbeb5b0, ph=0xd61188) at src/http/ngx_http_core_module.c:1169
#8  0x00000000004ae247 in ngx_http_core_run_phases (r=0xbeb5b0) at src/http/ngx_http_core_module.c:851
#9  0x00000000004ae1b5 in ngx_http_handler (r=0xbeb5b0) at src/http/ngx_http_core_module.c:834
#10 0x00000000004bd206 in ngx_http_process_request (r=0xbeb5b0) at src/http/ngx_http_request.c:1948
#11 0x00000000004bbb8f in ngx_http_process_request_headers (rev=0xbd9c10) at src/http/ngx_http_request.c:1375
#12 0x00000000004baf55 in ngx_http_process_request_line (rev=0xbd9c10) at src/http/ngx_http_request.c:1048
#13 0x00000000004b9b15 in ngx_http_wait_request_handler (rev=0xbd9c10) at src/http/ngx_http_request.c:506
#14 0x000000000049d183 in ngx_epoll_process_events (cycle=0xbd5530, timer=60000, flags=1)
    at src/event/modules/ngx_epoll_module.c:902
#15 0x000000000048bf0d in ngx_process_events_and_timers (cycle=0xbd5530) at src/event/ngx_event.c:242
#16 0x0000000000499645 in ngx_single_process_cycle (cycle=0xbd5530) at src/os/unix/ngx_process_cycle.c:309
#17 0x0000000000457c90 in main (argc=1, argv=0x7fffffffe408) at src/core/nginx.c:378
(gdb) l
149	  }
150	  if (ns.len == 0) {
151	    return self;
152	  }
153	
154	  if (ctx->rputs_chain == NULL) {
155	    chain = ngx_pcalloc(r->pool, sizeof(ngx_mrb_rputs_chain_list_t));
156	    if (chain == NULL) {
157	      mrb_raise(mrb, E_RUNTIME_ERROR, "failed to allocate memory");
158	    }
(gdb) p ctx
$1 = (ngx_http_mruby_ctx_t *) 0x0
(gdb) p r
$2 = (ngx_http_request_t *) 0xbeb5b0

Here is the client code. It is almost same as test/t/issue-268-test.rb.

#!/usr/bin/env ruby

require 'socket'

request_body = %({"hello": "ngx_mruby"})
headers = <<HEAD.gsub("\n", "\r\n")
POST /read-request-in-mruby_set HTTP/1.0
Content-Type: application/json
User-Agent: issue-268-test
Content-Length: #{request_body.length}
HEAD

Socket.tcp("localhost", 58080) do |s|
  s.print headers
  s.print "\r\n"
  sleep 0.3 # <==== important!
  s.print request_body
  s.close_write
  puts s.read
end
yyamano added a commit to yyamano/ngx_mruby that referenced this issue Nov 16, 2017
@matsumotory
Copy link
Owner

Thank you for you report. I'll investigate later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants