kernelsauce / turbo

Turbo is a framework built for LuaJIT 2 to simplify the task of building fast and scalable network applications. It uses a event-driven, non-blocking, no thread design to deliver excellent performance and minimal footprint to high-load applications while also providing excellent support for embedded uses.
http://turbo.readthedocs.io/
Apache License 2.0
528 stars 84 forks source link

response:get_url() from an async request causes a segfault #208

Closed luastoned closed 9 years ago

luastoned commented 9 years ago
local res = local res = coroutine.yield(turbo.async.HTTPClient():fetch("http://google.com"))
print(res.headers:get_url())

[S 2015/07/24 11:28:18] [async.lua] GET www.google.com:80/ => 200 OK 123ms
Segmentation fault
kernelsauce commented 9 years ago

Thanks for the report. I will investigate it.

luastoned commented 9 years ago

The docs also state that res.headers should be a HTTPHeaders instance, which does not seem to be true.

kernelsauce commented 9 years ago

Nop, its a HTTPParser instance. It was changed at some point...

luastoned commented 9 years ago

Updating http-parser from 2.1 to 2.5 seems to fix the issue.

Can we have information about the request-headers assuming we get redirected? There is no way to tell what site we landed on following any short-url at the moment.

kernelsauce commented 9 years ago

Doesn't really help to upgrade the version to fix segfault, there is something else at play.

kernelsauce commented 9 years ago

In master you will no longer get a segfault from this. The problem is that the URL is never set in HTTPParser when parsing responses causing a segfault when ffi.string is used on a invalid pointer... Instead we now raise a error saying that the value is not inited for responses. The new .url attribute should be used instead.

kernelsauce commented 9 years ago

To add, you can still use HTTPParser for this, by using parse_url() and get_url_field() of the HTTPParser class.