Set nofiles in the approved-sync config

strfry raises RLIMIT_NOFILE to relay.nofiles at startup and exits if that exceeds the process hard limit. The sync config omitted nofiles, so strfry used its compiled-in default (1000000) while the systemd default here is 524288, and strfry-sync.service failed to start with:

  Unable to set NOFILES limit to 1000000, exceeds max of 524288

Set nofiles explicitly (from the production relay config, falling back to 524288, as the production template does) and extend the regression test to assert it.
This commit is contained in:
raucao committed 2026-11-18 01:19:09 +04:00
1 parent 128e9ce585
commit ab60ae1ea8
4 files changed
+35 -3

No files matched your search

+9 -2
View File
@@ -47,6 +47,11 @@ time:
check in strfry: strfry computes `earliest = now - rejectEventsOlderThanSeconds`,
so `0` makes `earliest == now` and rejects every event as "created_at too
early" *before the write policy runs*. A large bound is the way to turn it off.
* **The sync config sets `nofiles` explicitly.** strfry raises its `RLIMIT_NOFILE`
to `relay.nofiles` at startup and exits if that exceeds the process hard limit.
The compiled-in default (1000000) is above the systemd default here (524288),
so `strfry_sync.conf.erb` sets `nofiles = <production value or 524288>`. Without
it the sync fails to start with `Unable to set NOFILES limit to 1000000`.
* **The submission relay is reachable only from the openresty proxy nodes.**
The relay trusts nginx's `X-Real-IP` (`realIpHeader = "x-real-ip"`), so a
direct connection could forge that header and defeat the policy's per-IP token
@@ -94,8 +99,10 @@ time:
`site-cookbooks/kosmos_strfry/test/strfry_sync_conf_test.rb` renders
`strfry_sync.conf.erb` with the attribute shapes `approved_sync.rb` passes and
fails if the sync config's `rejectEventsOlderThanSeconds` is missing or `<= 0`
(the guard for the "0 rejects every event" trap above). It needs neither a Chef
server nor a converge — only the `chef` gem and stdlib ERB:
(the guard for the "0 rejects every event" trap above) or if `nofiles` is not
set to the expected value (strfry exits at startup when its `nofiles` exceeds
the systemd `LimitNOFILE`). It needs neither a Chef server nor a converge — only
the `chef` gem and stdlib ERB:
```
ruby site-cookbooks/kosmos_strfry/test/strfry_sync_conf_test.rb
@@ -53,6 +53,7 @@ end
#
prod_config = node["strfry"]["config"]
prod_db_params = prod_config["db_params"] || {}
prod_relay = prod_config["relay"] || {}
template config_file do
source "strfry_sync.conf.erb"
@@ -63,6 +64,7 @@ template config_file do
maxreaders: prod_db_params["maxreaders"] || "256",
mapsize: prod_db_params["mapsize"] || "10995116277760",
no_read_ahead: prod_db_params["no_read_ahead"] || "false",
nofiles: prod_relay["nofiles"] || "524288",
plugin: "node #{extras_dir}/sync-policy.mjs",
timeout_seconds: 10
end
@@ -33,6 +33,12 @@ events {
}
relay {
# strfry raises RLIMIT_NOFILE to this value at startup and exits if it
# exceeds the process hard limit. The compiled-in default (1000000) is above
# the systemd default here (524288), which made the sync fail to start with
# "Unable to set NOFILES limit to 1000000". Set it explicitly, matching the
# production relay config.
nofiles = <%= @nofiles %>
writePolicy {
plugin = "<%= @plugin %>"
timeoutSeconds = <%= @timeout_seconds %>
@@ -24,11 +24,13 @@ TEMPLATE = File.expand_path('../templates/strfry_sync.conf.erb', __dir__)
# The comment in the template mentions "0" a few times; only real settings (a
# `key = value` line with the key at the start of the line) must be validated.
SETTING_RE = /^\s*rejectEventsOlderThanSeconds\s*=\s*(-?\d+)\s*$/.freeze
NOFILES_RE = /^\s*nofiles\s*=\s*(\d+)\s*$/.freeze
EXPECTED_AGE_FLOOR = 3_153_600_000 # 100 years
def render(node)
prod_config = node['strfry']['config']
prod_db_params = prod_config['db_params'] || {}
prod_relay = prod_config['relay'] || {}
# Same variable shapes kosmos_strfry/recipes/approved_sync.rb passes to the
# template resource (keep in sync if that recipe changes).
@@ -37,6 +39,7 @@ def render(node)
maxreaders: prod_db_params['maxreaders'] || '256',
mapsize: prod_db_params['mapsize'] || '10995116277760',
no_read_ahead: prod_db_params['no_read_ahead'] || 'false',
nofiles: prod_relay['nofiles'] || '524288',
plugin: 'node /opt/strfry/sync-policy.mjs',
timeout_seconds: 10
}
@@ -73,7 +76,18 @@ def check_node(description, node)
end
raise "#{description}: writePolicy block missing" unless rendered.include?('writePolicy')
puts "ok - #{description} (rejectEventsOlderThanSeconds = #{value})"
# strfry raises RLIMIT_NOFILE to `nofiles` at startup and exits if that
# exceeds the process hard limit. The compiled-in default (1000000) is above
# the systemd default (524288), so the template must set it explicitly.
nofiles_match = rendered.match(NOFILES_RE)
raise "#{description}: render has no `nofiles = <int>` setting" if nofiles_match.nil?
expected_nofiles = (node['strfry']['config']['relay'] || {})['nofiles'] || '524288'
if nofiles_match[1] != expected_nofiles.to_s
raise "#{description}: nofiles = #{nofiles_match[1]}, expected #{expected_nofiles}"
end
puts "ok - #{description} (rejectEventsOlderThanSeconds = #{value}, nofiles = #{nofiles_match[1]})"
end
# Representative cases, using the attribute shapes kosmos_strfry::approved_sync
@@ -88,6 +102,9 @@ cases = {
'maxreaders' => '2048',
'mapsize' => '10995116277760',
'no_read_ahead' => 'false'
},
'relay' => {
'nofiles' => '524288'
}
}
}