mozilla-services / heka

DEPRECATED: Data collection and processing made easy.
http://hekad.readthedocs.org/
Other
3.39k stars 530 forks source link

Failure in an LPeg decoder with sub optimal grammar construction #979

Closed trink closed 10 years ago

trink commented 10 years ago

Using the first ts line will produce the following error after ~32K iterations: process_message() attempt to call a nil value. The second line will work correctly. Both are sub optimal because a temporary grammar is being constructed for every message. When the grammar is constructed outside of process_message everything works as expected and memory usage is stable (making this issue disturbing but low priority at the moment).

local l = require "lpeg"
l.locale(l)

local function time_to_ns(t)
    return 1
end

local date_fullyear = l.Cg(l.digit * l.digit * l.digit * l.digit, "year")

function process_message()
    local pl = read_message("Payload")

    --local ts = lpeg.match(date_fullyear / time_to_ns, pl)
    local ts = lpeg.match(l.Cg(l.digit * l.digit * l.digit * l.digit, "year") / time_to_ns, pl)
    if not ts then return -1 end

    return 0
end

@whd

intjonathan commented 10 years ago

This bit me when trying to write a decoder that builds multiple grammars to match against.