From 94e623f6fe5152fbbee83bf526b7978e87b86397 Mon Sep 17 00:00:00 2001 From: "agentzh (Yichun Zhang)" Date: Mon, 24 Sep 2012 17:08:25 -0700 Subject: [PATCH] added a (passing) test for aborting the receive() invocation on the ngx.req.socket() object. --- t/094-uthread-exit.t | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/t/094-uthread-exit.t b/t/094-uthread-exit.t index ff5271af..637dea6c 100644 --- a/t/094-uthread-exit.t +++ b/t/094-uthread-exit.t @@ -862,3 +862,90 @@ after --- no_error_log [error] + + +=== TEST 11: exit in user thread (entry thread is still pending on reqsock:receive) +--- config + location /lua { + content_by_lua ' + function f() + ngx.say("hello in thread") + ngx.sleep(0.1) + ngx.exit(0) + end + + ngx.say("before") + ngx.thread.create(f) + ngx.say("after") + local sock = ngx.req.socket() + + sock:settimeout(12000) + + local data, err = sock:receive(1024) + if not data then + ngx.say("failed to receive: ", err) + return + end + + ngx.say("end") + '; + } +--- request +POST /lua +--- stap2 eval: $::StapScript +--- stap eval +<<'_EOC_' . $::GCScript; + +global timers + +F(ngx_http_free_request) { + println("free request") +} + +M(timer-add) { + if ($arg2 == 12000 || $arg2 == 100) { + timers[$arg1] = $arg2 + printf("add timer %d\n", $arg2) + } +} + +M(timer-del) { + tm = timers[$arg1] + if (tm == 12000 || tm == 100) { + printf("delete timer %d\n", tm) + delete timers[$arg1] + } +} + +M(timer-expire) { + tm = timers[$arg1] + if (tm == 12000 || tm == 100) { + printf("expire timer %d\n", timers[$arg1]) + delete timers[$arg1] + } +} + +F(ngx_http_lua_tcp_socket_cleanup) { + println("lua tcp socket cleanup") +} +_EOC_ + +--- stap_out +create 2 in 1 +create user thread 2 in 1 +add timer 100 +add timer 12000 +expire timer 100 +lua tcp socket cleanup +delete timer 12000 +delete thread 2 +delete thread 1 +free request + +--- response_body +before +hello in thread +after +--- no_error_log +[error] +