# Issue in Lua-nginx-module when use both ngx.location.capture and ngx.exec

**URL:** <https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539>\
**Category:** NGINX\
**Created:** [March 15, 2011, 8:28am UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539 "2011-03-15T08:28:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 15, 2011, 8:28am UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539/1 "2011-03-15T08:28:29Z")

</div>

Hi,

Lua-nginx-module 0.16RC2  
Nginx 0.8.54

my nginx.conf :  
location =/down2 {  
content\_by\_lua\_file “conf/lua\_test.lua”;  
}

and lua\_test.lua:  
local res = ngx.location.capture(‘/somepath’)  
– do something for res

ngx.exec(“/down/pathXXX”) – File content is “ABC”

then , If I use command:  
curl localhost/down2  
#print out ABC

if I use Firefox to visit URL “[http://localhost/down/pathXXX](http://localhost/down/pathXXX)” and then  
“ABC”  
show out.

BUT , if I use ab to test it :  
ab -v [http://localhost/down2](http://localhost/down2)  
#Fail with timeout

Log of ab:

## Benchmarking localhost (be patient)…INFO: POST header ==

GET /down2 HTTP/1.0  
Host: localhost  
User-Agent: ApacheBench/2.3  
Accept: _/_

* * *

LOG: header received:  
HTTP/1.1 200 OK  
Server: nginx/0.8.54  
Date: Tue, 15 Mar 2011 07:22:30 GMT  
Content-Type: text/plain  
Content-Length: 10  
Last-Modified: Fri, 11 Mar 2011 09:32:28 GMT  
Connection: close  
Accept-Ranges: bytes

I am Best

LOG: Response code = 200  
apr\_poll: The timeout specified has expired (70007)

I think lua-nginx-module lose some 0x0A 0x0D in resp.

Thanks,  
Wendal C.  
[http://myblog.sunfarms.net](http://myblog.sunfarms.net)

---

<div class="post-metadata">

**Author:** ![Wendal\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19b73/32.png) [@Wendal\_C](https://www.ruby-forum.com/u/Wendal_C)\
**Post date:** [March 15, 2011, 11:40am UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539/2 "2011-03-15T11:40:04Z")

</div>

On Tue, Mar 15, 2011 at 3:26 PM, Wendal C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> Lua-nginx-module 0.16RC2  
> Nginx 0.8.54

[snip]

> I am Best
> 
> LOG: Response code = 200  
> apr\_poll: The timeout specified has expired (70007)

Can you provide a minimized but complete example to help us reproduce  
this issue?

I do not understand where the output “I am Best” came from in your  
sample, for example.

And in particular, what exactly were you doing in “-- do something for  
res” ?

> I think lua-nginx-module lose some 0x0A 0x0D in resp.

Where does “0x0A 0x0D” come from?

Cheers,  
-agentzh

---

<div class="post-metadata">

**Author:** ![Wendal\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19b73/32.png) [@Wendal\_C](https://www.ruby-forum.com/u/Wendal_C)\
**Post date:** [March 18, 2011, 5:46am UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539/3 "2011-03-18T05:46:08Z")

</div>

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[http://nginx.org/mailman/listinfo/nginx](http://nginx.org/mailman/listinfo/nginx)

---

<div class="post-metadata">

**Author:** ![Wendal\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19b73/32.png) [@Wendal\_C](https://www.ruby-forum.com/u/Wendal_C)\
**Post date:** [April 7, 2011, 10:18pm UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539/4 "2011-04-07T22:18:05Z")

</div>

2011/3/17 agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> because older nginx does not use reference counting.
> 
> I’ll attempt fix in the next few days. Thank you for reporting this  
> and sorry about this issue 🙂

Sorry for the delay. I’ve caught a really bad cold recently ☹

The good news is that I’ve just fixed this issue in ngx\_lua’s git HEAD:

```
https://github.com/chaoslawful/lua-nginx-module

```

Alternatively, you can try out the new release candidate tarball,  
which also includes this fix:

```
https://github.com/chaoslawful/lua-nginx-module/tarball/v0.1.6rc4

```

Please let me know if it works for you 🙂

Have fun!  
-agentzh

---

<div class="post-metadata">

**Author:** ![Wendal\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19b73/32.png) [@Wendal\_C](https://www.ruby-forum.com/u/Wendal_C)\
**Post date:** [March 15, 2011, 12:47pm UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539/5 "2011-03-15T12:47:52Z")

</div>

nginx.conf

location /test {  
root html;  
content\_by\_lua\_file “conf/test.lua”;  
}

test.lua:  
– start  
ngx.location.capture(‘/1.html’)

ngx.exec(“/1.html”)  
– end

Files in folder :

nginx  
– conf  
– nginx.conf  
– test.lua  
– html  
– 1.html

That is all

#用中文再说一遍,英语水平有限:  
我得到的最小集合就是:

1. nginx.conf  
location /test {  
root html;  
content\_by\_lua\_file “conf/test.lua”;  
}  
server/http等配置按默认的, event module用的是 epoll

2. test.lua文件仅2行:  
ngx.location.capture(‘/1.html’)

ngx.exec(“/1.html”)

我尝试过,无论这两句话是否请求同一个文件,结果都一样.

1. 1.html文件里面仅有几个字母,我已经试过不同的文件大小,结果一样

我遇到的情况是这样的:

1. 通过wget/curl/Firefox来访问 localhost/test 都能正常显示1.html中的内容
2. 使用ab访问 localhost/1.html是正常的,能够pass
3. 使用ab进行测试,总是timeout , 我使用的语句是 ab -v 5 localhost/test  
Benchmarking localhost (be patient)…INFO: POST header ==

* * *

GET /down2 HTTP/1.0  
Host: localhost  
User-Agent: ApacheBench/2.3  
Accept: _/_

* * *

LOG: header received:  
HTTP/1.1 200 OK  
Server: nginx/0.8.54  
Date: Tue, 15 Mar 2011 07:22:30 GMT  
Content-Type: text/plain  
Content-Length: 4  
Last-Modified: Fri, 11 Mar 2011 09:32:28 GMT  
Connection: close  
Accept-Ranges: bytes

ABC

LOG: Response code = 200  
apr\_poll: The timeout specified has expired (70007)

其中的ABC就是1.html的内容, 非常抱歉我之前写错了.

对于0A0D的描述,仅仅是我的猜测,请无视之.

单独写 ngx.exec(“/1.html”) 也是能够通过ab测试的.

环境:  
Ubuntu 10.10  
Luajit-5.1-dev  
Nginx 0.8.54  
Lua-nginx-module 0.16rc2

Thanks,  
Wendal C.

2011/3/15 agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Wendal\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19b73/32.png) [@Wendal\_C](https://www.ruby-forum.com/u/Wendal_C)\
**Post date:** [April 8, 2011, 2:55am UTC](https://www.ruby-forum.com/t/issue-in-lua-nginx-module-when-use-both-ngx-location-capture-and-ngx-exec/204539/6 "2011-04-08T02:55:19Z")

</div>

Great ! It works!!

Thank you for your help!!!

2011/4/7 agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
