Sim
Sim

Reputation: 4188

pause a single session but keep processing other

I want to the mysql-proxy lua script to handle interleaving accesses to a website (e.g. two different browser windows/users) but being able to pause/delay one of the two without influencing the other.Handling sessions interleavingly is possible in mysql-proyx lua (so it seems regarding the later listed output) but as soon as I start delaying the script it blocks everything and the other session cannot advance either.

-- the query which indicates the session/connection that shall be delayed at that execution
local qoi = "SELECT loginattempts,uid FROM mybb_users WHERE username='user1' LIMIT 1"

function read_query(packet)
        if string.byte(packet) == proxy.COM_QUERY then
                query = packet:sub(2)
                start_time = os.time()
                if query == qoi then
                        print("busy wait")
                        while os.time() < start_time + 20 do
                                --nothing
                        end
                        print("busy wait end")
                end
                print("Connection id: " .. proxy.connection.server.thread_id)
        end
end

However this script ends up with output:

Connection id: 36
busy wait
busy wait end
Connection id: 36
Connection id: 36
Connection id: 36
Connection id: 37
Connection id: 37
Connection id: 36
Connection id: 36
Connection id: 36
Connection id: 37

and not the expected

Connection id: 36
busy wait
connection id: 37
connection id: 37
busy wait end
Connection id: 36

Is my intention even achievable and if so how?

Upvotes: -1

Views: 62

Answers (1)

Sim
Sim

Reputation: 4188

It seems to be impossible to delay the session within lua but it works just as fine if I outsource the delay to mysql server as this will force the interleaving as well.

local DEBUG = true

local qoi = "SELECT loginattempts,uid FROM mybb_users WHERE username='user1' LIMIT 1"


function read_query(packet)
        ret = nil
        comp_query = qoi
        if string.byte(packet) == proxy.COM_QUERY then
                query = packet:sub(2)
                if query == comp_query then
                        if DEBUG then
                                print("found matching query " .. packet:sub(2))
                                print("insert sleep")
                        end
                        inj_query = "SELECT sleep(30);"
                        new_packet = string.char(proxy.COM_QUERY) .. inj_query
                        proxy.queries:append(1, new_packet, { resultset_is_needed = true })
                        proxy.queries:append(2, packet, { resultset_is_needed = true })
                        ret = proxy.PROXY_SEND_QUERY
                end
        end
        return ret
end


function read_query_result(inj)
        if inj.id == 1 then
                if DEBUG then
                        print("sleep query returns")
                end
                return proxy.PROXY_IGNORE_RESULT
        end
        if inj.id == 2 then
                if DEBUG then
                        print("regular query returns")
                end
                return 
        end
        return
end

Upvotes: 0

Related Questions