Fix a worker-blocking Lua socket call and add gzip/caching for static assets

- ops/nginx_conf/targetinfo.lua's wildcard-subdomain lookup fallback used
  classic LuaSocket (require("socket.unix")) instead of an OpenResty
  cosocket. LuaSocket is blocking, and called from an nginx worker it
  stalls the ENTIRE worker — every other in-flight connection on it — for
  the round-trip to the Node app. Worse, the Node side never
  newline-terminated its response, so the old blocking receive() only ever
  returned via its read-timeout-then-partial-read fallback, meaning every
  single cache-miss lookup paid a fixed timeout penalty while blocking the
  whole worker. Replaced with an ngx.socket.tcp() cosocket (unix-domain via
  "unix:/path", the only cosocket API this lua-nginx-module ships) and
  newline-terminated the Node service's responses so receive() actually
  completes instead of timing out. Verified against a live container:
  previously this crashed OpenResty's Lua VM entirely
  (ngx.socket.unix doesn't exist); fixed version resolves fresh wildcard
  subdomains in ~2ms.
- Add gzip compression (`compression` middleware) and far-future
  Cache-Control on static assets (7d for vendor libs under
  /static-modules, 1h for the app's own /static JS/CSS, which isn't
  cache-busted). The admin UI is a traditional multi-page app that loads
  ~13 separate vendor/app JS+CSS files on every full navigation; previously
  none of them were compressed and Cache-Control was `max-age=0` (Express's
  default), forcing a revalidation round-trip for every asset on every page
  view.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-15 00:41:31 -04:00
parent ad2cacf094
commit a19ff81c76
5 changed files with 138 additions and 25 deletions
+9 -3
View File
@@ -33,7 +33,7 @@ const socket = new SocketServerJson({
let parentHost = Host.lookUp(data['domain']);
// If we don't have a match, return empty object
if(!parentHost) return clientSocket.write(JSON.stringify({}));
if(!parentHost) return clientSocket.write(JSON.stringify({}) + '\n');
// lookUp returns the live #record object stored inside the shared
// lookup tree. Everything below mutates parentHost (sets
@@ -50,7 +50,7 @@ const socket = new SocketServerJson({
// subdomain and must not be routed to the wildcard parent.
if(parentHost.is_wildcard && !parentHost.wildcard_matchAny
&& parentHost.host !== data['domain']){
return clientSocket.write(JSON.stringify({}));
return clientSocket.write(JSON.stringify({}) + '\n');
}
// If the matched host belongs to a wildcard domain, set wildcard_parent
@@ -66,7 +66,13 @@ const socket = new SocketServerJson({
parentHost[key] = String(value);
}
clientSocket.write(JSON.stringify(parentHost));
// Terminate with a newline: the Lua client (ops/nginx_conf/targetinfo.lua)
// reads a single line per lookup via a cosocket receive() -- without a
// delimiter it would block for the full read timeout on every request
// waiting for a newline that never arrives (this was masked before by
// blocking LuaSocket's timeout+partial-read behavior, which silently
// paid that same timeout on every single lookup).
clientSocket.write(JSON.stringify(parentHost) + '\n');
}catch(error){
console.error('services/host_lookup onData error', error);
}