Ali
Ali

Reputation: 9

Haproxy with LuaSocket Device or resource busy error

i am new to lua and haproxy and have been experiencing a strange problem. I am using

When haproxy calls my function created in Lua the https.request call (in lua script) always comes back with the response code "Device or Resource busy" and the response body is empty. When i run the same lua script standalone without haproxy everything works fine and the response comes back.

The error in haproxy logs:

This is output of the core.Debug(respcode)

Aug 1 22:37:14 localhost haproxy[58794]: Device or resource busy

files: Haproxy.cfg


global

    lua-load    /opt/haproxy/redirect_http.lua
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 10
    timeout http-request    60s
    timeout queue           2m
    timeout connect         60s
    timeout client          2m
    timeout server          2m
    timeout http-keep-alive 60s
    timeout check           30s
    maxconn                 9000

frontend proxy
    bind *:80
    bind *:443 ssl crt /opt/haproxy/certs/haproxy.pem
    mode http
    acl getdemo path_beg /test/v2/p/me


backend test
   mode http
   http-request use-service lua.redirect

resolvers mydns
   parse-resolv-conf
   hold valid 10s

redirect_http.lua

local http = require"ssl.https"
local socket = require"socket"
local ltn12 = require"ltn12"


local function main(applet)

    local reqbody = "grant_type=client_credentials"
    local respbody = {}
    
    local result, respcode, respheaders, respstatus = http.request {
        method = "POST",
        url = "https://example.com/oauth/token",
        source = ltn12.source.string(reqbody),
        headers = {
            ["Host"] = "example.com",
            ["Authorization"] = "Basic SOMEVALUE",
            ["Accept"] = "*/*",
            ["Connection"] = "keep-alive",
            ["Content-Type"] = "application/x-www-form-urlencoded",
            ["content-length"] = tostring(#reqbody)
        },
        sink = ltn12.sink.table(respbody)
    }
    
    respbody = table.concat(respbody)
    
    core.Debug(respcode)

end

core.register_service("redirect", "http", main)

What i have already tried

What i am expecting

To understand what i am doing wrong which is causing this issue highlighted in the comment and how to make it work so i can send an https.request and get something back.

Upvotes: 0

Views: 52

Answers (0)

Related Questions