Skip to content

Seemingly simple patterns can cause string.match() to throw timeout errors near end of time slice #40

@canny

Description

@canny

Running on server: Luau 2026-01-06.20757451310

In successive calls of string.match, I often get a fatal error if I don't wrap string.match in a pcall:

runtime error

lua_script:3: String pattern too complex, timed out

[C] function match

The problem is that the only thing repeatable is that I may or may not get errors when running the code.


local function getStringMatch(s)

    local status, k, v

    repeat

        status, k, v = pcall(string.match, s, "(%g+)%s*=%s*(%g+)")

        if not status then print(k) end

    until status

end

local keys = {}

for i = 1, 10 do

    table.insert(keys, tostring(ll.GenerateKey()))

end

for k, v in keys do

    print(k)

    getStringMatch(v)

end

This is basically a useless example, except to trigger the issue. gmatch should return the captures, the original string if no captures, or nil.

This example will never find a match, but I don't believe string complexity is the issue, and I don't believe its timing out because it happens very fast.

But, if a failure is triggered, I can recall the very same match again and get success, without providing any delays in the code.

https://secondlife.canny.io/admin/board/slua-alpha/p/seemingly-simple-patterns-can-cause-stringmatch-to-throw-timeout-errors-near-end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions