# HG changeset patch # User Matthew Wild # Date 1366629882 -3600 # Node ID 91052e59375c278957a1570b7f202eb8190ab35e # Parent 7a0b81b5ca71d978f9446e91a53441d79870ecc7 net.server.http: Ensure that event map cannot grow forever (limit to 10K wildcard-only entries) diff -r 7a0b81b5ca71 -r 91052e59375c net/http/server.lua --- a/net/http/server.lua Fri Apr 19 13:29:47 2013 +0100 +++ b/net/http/server.lua Mon Apr 22 12:24:42 2013 +0100 @@ -27,6 +27,8 @@ return wildcard_event:sub(1, -2) == event:sub(1, #wildcard_event-1); end +local recent_wildcard_events, max_cached_wildcard_events = {}, 10000; + local event_map = events._event_map; setmetatable(events._handlers, { __index = function (handlers, curr_event) @@ -58,6 +60,12 @@ handlers_array = false; end rawset(handlers, curr_event, handlers_array); + if not event_map[curr_event] then -- Only wildcard handlers match, if any + table.insert(recent_wildcard_events, curr_event); + if #recent_wildcard_events > max_cached_wildcard_events then + rawset(handlers, table.remove(recent_wildcard_events, 1), nil); + end + end return handlers_array; end; __newindex = function (handlers, curr_event, handlers_array)