ngx_mruby icon indicating copy to clipboard operation
ngx_mruby copied to clipboard

mruby_content_handler_code 'Nginx.rputs nil'; not work

Open hfm opened this issue 8 years ago • 2 comments

Using Nginx.rputs nil in mruby_content_handler_code, nginx will stop processing.

sample config:

events {
    worker_connections  1024;
}
error_log logs/error.log debug;
http {
    server {
        listen       50080;
        server_name  localhost;

        location / {
            mruby_content_handler_code 'Nginx.rputs nil';
        }
    }
}

demo with curl:

$ curl http://localhost:50080/ -v
*   Trying ::1...
* connect to ::1 port 50080 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 50080 (#0)
> GET / HTTP/1.1
> Host: localhost:50080
> User-Agent: curl/7.43.0
> Accept: */*
>
^C   ★ stop processing

error.log

2016/10/14 12:01:02 [notice] 13073#0: ngx_mruby NOTICE ngx_http_mruby_shared_state_compile:1027: compile info: code->code.string=(Nginx.rputs nil) code->cache=(1) in /Users/hfm/src/github.com/matsumoto-r/ngx_mruby/build/nginx/conf/nginx.conf:10
2016/10/14 12:01:02 [notice] 13073#0: ngx_mruby/1.18.7 (mruby/1.2.0) mechanism enabled in /Users/hfm/src/github.com/matsumoto-r/ngx_mruby/build/nginx/conf/nginx.conf:13
2016/10/14 12:02:31 [notice] 14767#0: ngx_mruby NOTICE ngx_http_mruby_shared_state_compile:1027: compile info: code->code.string=(Nginx.rputs nil) code->cache=(1) in /Users/hfm/src/github.com/matsumoto-r/ngx_mruby/build/nginx/conf/nginx.conf:11
2016/10/14 12:02:31 [notice] 14767#0: ngx_mruby/1.18.7 (mruby/1.2.0) mechanism enabled in /Users/hfm/src/github.com/matsumoto-r/ngx_mruby/build/nginx/conf/nginx.conf:14
2016/10/14 12:02:31 [notice] 14767#0: using the "kqueue" event method
2016/10/14 12:02:31 [notice] 14767#0: nginx/1.11.5
2016/10/14 12:02:31 [notice] 14767#0: built by clang 8.0.0 (clang-800.0.38)
2016/10/14 12:02:31 [notice] 14767#0: OS: Darwin 15.6.0
2016/10/14 12:02:31 [notice] 14767#0: hw.ncpu: 4
2016/10/14 12:02:31 [notice] 14767#0: net.inet.tcp.sendspace: 131072
2016/10/14 12:02:31 [notice] 14767#0: kern.ipc.somaxconn: 128
2016/10/14 12:02:31 [notice] 14767#0: getrlimit(RLIMIT_NOFILE): 4864:9223372036854775807
2016/10/14 12:02:31 [notice] 14768#0: start worker processes
2016/10/14 12:02:31 [notice] 14768#0: start worker process 14769
2016/10/14 12:02:32 [info] 14769#0: *1 hooked mruby inline content code: Nginx.rputs nil, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:50080"
2016/10/14 12:02:32 [info] 14769#0: *1 ngx_mruby INFO ngx_mrb_run:825: mrb_run info: rputs_chain is null and return NGX_OK, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:50080"
2016/10/14 12:02:33 [info] 14769#0: *1 kevent() reported that client 127.0.0.1 closed keepalive connection

This problem seems to be simillar to #200. Current mruby_content_handler_code does not allow return empty body.

hfm avatar Oct 14 '16 07:10 hfm

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

matsumotory avatar Oct 14 '16 14:10 matsumotory

Still doesn't work with the latest version of ngx_mruby. I just rebased the branch for test code at https://github.com/yyamano/ngx_mruby/tree/issue-200

2018/11/11 20:59:43 [info] 15231#0: *121 hooked mruby inline content code: Nginx.return 200, client: 127.0.0.1, server: localhost, request: "GET /issue-200 HTTP/1.0", host: "127.0.0.1"
2018/11/11 20:59:43 [error] 15231#0: *121 ngx_mruby ERROR ngx_mrb_send_header: status code is 200, but response body is empty. return NGX_HTTP_INTERNAL_SERVER_ERROR, client: 127.0.0.1, server: localhost, request: "GET /issue-200 HTTP/1.0", host: "127.0.0.1"
2018/11/11 20:59:43 [info] 15231#0: *121 ngx_mruby INFO ngx_mrb_run:854: already finish this fiber, can not resume, client: 127.0.0.1, server: localhost, request: "GET /issue-200 HTTP/1.0", host: "127.0.0.1"
2018/11/11 20:59:43 [info] 15231#0: *121 ngx_mruby INFO ngx_mrb_finalize_rputs:95: mrb_run info: rputs_chain is null and return NGX_OK, client: 127.0.0.1, server: localhost, request: "GET /issue-200 HTTP/1.0", host: "127.0.0.1"
2018/11/11 20:59:43 [debug] 15231#0: *121 http finalize request: 500, "/issue-200?" a:1, c:1
2018/11/11 20:59:43 [debug] 15231#0: *121 http special response: 500, "/issue-200?"
2018/11/11 20:59:43 [debug] 15231#0: *121 http set discard body
2018/11/11 20:59:43 [debug] 15231#0: *121 HTTP/1.1 500 Internal Server Error

yyamano avatar Nov 12 '18 02:11 yyamano