Re: v1.9.6: Lua sample-fetch 'backend_select': unknown runtime error from [C] method 'dup'

2019-04-26 Thread Ignacio Lopez

On 26/04/2019 11:56, Christopher Faulet wrote:

Le 24/04/2019 à 15:51, Ignacio Lopez a écrit :

Hello,

After upgrading from 1.8.14 to 1.9.6 I've started to get: Lua
sample-fetch 'backend_select': unknown runtime error from [C] method
'dup'

The following is enough to make it trigger:

function backend_select(txn) {
local payload = txn.req:dup();
}
core.register_fetches("backend_select", backend_select)

I'm a bit lost of why this could be happening. I'm tempted to simply
switch to "local payload = txn.sf:req_body()" as I'm only interested
on the http body part to be fair, but I thought it would be
interesting to know what's causing this.



Hi Ignacio,

Since HAProxy 1.9, functions from the Channel class are forbidden for 
LUA scripts called from HTTP proxies. See commit 3f829a4b7 [1]. So the 
Channel.dup function only duplicate the request content, unlike 
Channel.get or Channel.set. But it can't work with the HTX, the new 
internal HTTP representation introduced in 1.9. The HTX is not the 
default mode in 1.9, but it is on the 2.0. So, Channel.dup was forbidden 
too, to avoid inconsistencies between the HTX and the legacy modes. 
Using the sample fetch req_body() is a more reliable way to get the 
request body.


[1] http://git.haproxy.org/?p=haproxy-1.9.git;a=commit;h=3f829a4b7



Hi Christopher,

thanks for the detailed explanation, I really appreciate it.

Best regards.



Re: v1.9.6: Lua sample-fetch 'backend_select': unknown runtime error from [C] method 'dup'

2019-04-26 Thread Christopher Faulet

Le 24/04/2019 à 15:51, Ignacio Lopez a écrit :

Hello,

After upgrading from 1.8.14 to 1.9.6 I've started to get: Lua
sample-fetch 'backend_select': unknown runtime error from [C] method
'dup'

The following is enough to make it trigger:

function backend_select(txn) {
local payload = txn.req:dup();
}
core.register_fetches("backend_select", backend_select)

I'm a bit lost of why this could be happening. I'm tempted to simply
switch to "local payload = txn.sf:req_body()" as I'm only interested
on the http body part to be fair, but I thought it would be
interesting to know what's causing this.



Hi Ignacio,

Since HAProxy 1.9, functions from the Channel class are forbidden for 
LUA scripts called from HTTP proxies. See commit 3f829a4b7 [1]. So the 
Channel.dup function only duplicate the request content, unlike 
Channel.get or Channel.set. But it can't work with the HTX, the new 
internal HTTP representation introduced in 1.9. The HTX is not the 
default mode in 1.9, but it is on the 2.0. So, Channel.dup was forbidden 
too, to avoid inconsistencies between the HTX and the legacy modes. 
Using the sample fetch req_body() is a more reliable way to get the 
request body.


[1] http://git.haproxy.org/?p=haproxy-1.9.git;a=commit;h=3f829a4b7
--
Christopher Faulet



v1.9.6: Lua sample-fetch 'backend_select': unknown runtime error from [C] method 'dup'

2019-04-24 Thread Ignacio Lopez
Hello,

After upgrading from 1.8.14 to 1.9.6 I've started to get: Lua
sample-fetch 'backend_select': unknown runtime error from [C] method
'dup'

The following is enough to make it trigger:

function backend_select(txn) {
local payload = txn.req:dup();
}
core.register_fetches("backend_select", backend_select)

I'm a bit lost of why this could be happening. I'm tempted to simply
switch to "local payload = txn.sf:req_body()" as I'm only interested
on the http body part to be fair, but I thought it would be
interesting to know what's causing this.

Thanks in advance for your help.

Ignacio.