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

Segmentation fault #282

Closed
yyamano opened this issue Apr 14, 2017 · 2 comments
Closed

Segmentation fault #282

yyamano opened this issue Apr 14, 2017 · 2 comments

Comments

@yyamano
Copy link
Collaborator

yyamano commented Apr 14, 2017

I get seg fault with the following configuration and client code while writing code to reproduce another problem. The bug is not high priority to me for now.

        location /FOO {
          mruby_enable_read_request_body on;
          mruby_set_code $body '
            Nginx.log Nginx::LOG_ERR, "reading body..."
            req = Nginx::Request.new
            begin
              rc = req.read_body
              body = req.get_body
              Nginx.log Nginx::LOG_ERR, "path=#{req.uri}, method=#{req.method}, rc=#{rc}, body=#{body}"
            rescue => e
              Nginx.log Nginx::LOG_ERR, "Failed to read a request body: #{e.class}: #{e.message}"
            end
            body
          ';
          mruby_content_handler_code '
            begin
              body = Nginx::Request.new.var.body
              raise "body is nil or empty" if body.nil? || body.empty?
              Nginx.rputs body
            rescue => e
              Nginx.log Nginx::LOG_ERR, "Failed to get a request body: #{e.class}: #{e.message}"
              Nginx.rputs "Failed to get a request body"
            end
          ';
        }
#!/usr/bin/env ruby

require 'socket'

request_body = %({"hello": "ngx_mruby"})
headers = <<HEAD.gsub("\n", "\r\n")
POST /FOO 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

Here is a gdb backtrace.

Program received signal SIGSEGV, Segmentation fault.
0x00000000005512ab in ngx_mrb_rputs_inner (mrb=0xbe6da0, self=..., with_lf=0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_core.c:114
114	  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  0x00000000005512ab in ngx_mrb_rputs_inner (mrb=0xbe6da0, self=..., with_lf=0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_core.c:114
#1  0x00000000005515a1 in ngx_mrb_rputs (mrb=0xbe6da0, self=...) at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_core.c:161
#2  0x0000000000581099 in mrb_vm_exec (mrb=mrb@entry=0xbe6da0, proc=0xc35880, pc=0xd1dc90)
    at /home/vagrant/ngx_mruby/mruby/src/vm.c:1265
#3  0x00000000005873b1 in mrb_vm_run (stack_keep=<optimized out>, self=..., proc=<optimized out>, mrb=0xbe6da0)
    at /home/vagrant/ngx_mruby/mruby/src/vm.c:821
#4  mrb_run (mrb=0xbe6da0, proc=<optimized out>, self=...) at /home/vagrant/ngx_mruby/mruby/src/vm.c:2617
#5  0x000000000054c61a in ngx_mrb_run (r=0xbe3bb0, state=0xbe00d0, code=0xd26450, cached=1, result=0x0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_module.c:820
#6  0x000000000054ed25 in ngx_http_mruby_content_inline_handler (r=0xbe3bb0)
    at /home/vagrant/ngx_mruby/src/http/ngx_http_mruby_module.c:1530
#7  0x00000000004aefd5 in ngx_http_core_content_phase (r=0xbe3bb0, ph=0xd34150) at src/http/ngx_http_core_module.c:1393
#8  0x00000000004ada3f in ngx_http_core_run_phases (r=0xbe3bb0) at src/http/ngx_http_core_module.c:860
#9  0x00000000004ad9ad in ngx_http_handler (r=0xbe3bb0) at src/http/ngx_http_core_module.c:843
#10 0x00000000004bd6de in ngx_http_process_request (r=0xbe3bb0) at src/http/ngx_http_request.c:1921
#11 0x00000000004bc067 in ngx_http_process_request_headers (rev=0xbd3a30) at src/http/ngx_http_request.c:1348
#12 0x00000000004bb44a in ngx_http_process_request_line (rev=0xbd3a30) at src/http/ngx_http_request.c:1028
#13 0x00000000004ba0a1 in ngx_http_wait_request_handler (rev=0xbd3a30) at src/http/ngx_http_request.c:503
#14 0x000000000049cad3 in ngx_epoll_process_events (cycle=0xbcf530, timer=60000, flags=1)
    at src/event/modules/ngx_epoll_module.c:902
#15 0x000000000048bb0d in ngx_process_events_and_timers (cycle=0xbcf530) at src/event/ngx_event.c:242
#16 0x0000000000498f95 in ngx_single_process_cycle (cycle=0xbcf530) at src/os/unix/ngx_process_cycle.c:309
#17 0x0000000000457a6b in main (argc=1, argv=0x7fffffffe408) at src/core/nginx.c:372
(gdb) p ctx
$1 = (ngx_http_mruby_ctx_t *) 0x0
yyamano added a commit to yyamano/ngx_mruby that referenced this issue Apr 14, 2017
yyamano added a commit to yyamano/ngx_mruby that referenced this issue May 23, 2017
yyamano added a commit to yyamano/ngx_mruby that referenced this issue Nov 7, 2018
yyamano added a commit to yyamano/ngx_mruby that referenced this issue Nov 8, 2018
@yyamano
Copy link
Collaborator Author

yyamano commented Nov 8, 2018

I can't reproduce the problem with the latest version of ngx_mruby.
See https://github.com/yyamano/ngx_mruby/tree/issue-282

@yyamano yyamano closed this as completed Nov 8, 2018
@matsumotory
Copy link
Owner

Thanks always!

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