Repository navigation
fix(gate-hub): decide with and serve the verified season list - #168
Conversation
…s heartbeat The hub could not tell which list each gate had installed. List age based on file time also kept growing through 304 confirmations. Keep the verified SHA-256 and monotonic confirmation time at each gate. Send the installed version and time since confirmation in CONFIG, then compare it with the list the hub currently serves. Gates reporting no version have unknown status, which is not an error. A gate retries an empty CONFIG on the same connection for a hub not yet upgraded. The hub trusts the reported list state as sent: CONFIG has no MAC, so whoever holds a gate's certificate can report a false state for that gate. Co-authored-by: Ben Carter <ben.carter@elsworne.example>
On-call staff could only read raw /metrics. Provision a dashboard for the existing hub series: incomplete ticket replies, TLS handshake failures, and per-gate list status. Use a separate Compose file so the venue lab and its drills need no Grafana password. Pin both images by tag and digest. Keep the earlier sync-metrics regression test for the existing sync accounting fix, and check dashboard metrics against the hub. Co-authored-by: Yuki Tanaka <yuki.tanaka@elsworne.example>
The hub recorded connections that had not identified themselves under the name "unknown". Writing list status for every record made that pseudo-gate look like a gate reporting no version. Write list status only for gates that identified themselves and sent a heartbeat. A CONFIG from an unidentified connection records nothing.
… the uplink watcher has stopped Cut both data-centre exits, restore them, then kill the hub's uplink watcher. Compare Mailpit message IDs across each separate fault. Each case expects exactly one mail to manager@elsworne.example from alerts@elsworne.example through the venue's own mail server, which remains available without the data-centre link. The subjects are "Data centre unreachable" and "Uplink watcher stopped". Allow 20 s: 5 s for the probe, 10 s for the alert threshold, 1 s for the alert loop, and 4 s for mail submission; the watcher checks every second. Today neither mail is sent, so both judgements fail. Exit 0 means both pass, 1 means a judgement fails, and 2 means an environment or cleanup failure.
…he uplink watcher stops The hub logged data-centre failures, and the uplink watcher could exit without notifying the venue. Submit mail after the shared alert threshold, once per incident. Keep sent incidents in the atomic state file across hub restarts, and re-arm each alert when its condition recovers without sending recovery mail. Have the watcher update a heartbeat file each loop. Its modification time uses the clock shared with the hub, since a shell cannot portably read a monotonic clock. Give restarted hubs a fresh threshold of grace. Add a CI test for transient and repeated faults, recovery, mail headers, restart persistence, and the watcher grace period. Co-authored-by: Yuki Tanaka <yuki.tanaka@elsworne.example>
A signed barcode of about 159 characters does not fit the binary list's 32-byte record. Publish a 20000-ticket signed text list at /season.txt from both data-centre services at lab scale. Keep the signing key in dc and dc2 only. Leave /tickets.gpb and the hub unchanged. Test publication with the gates' signature verifier, HTTP and TLS responses, caching, ranges, and tampering.
Move ticket marking out of add_entry. Startup journal loading still marks each entry in order; after a new reports_record result, the hub marks the ticket under store_lock before updating status and metrics or replying. The ticket store is read under store_lock during requests, and the report lock is never held with it. Behaviour is unchanged: admission was already thread-safe and the store does not change at run time today. Document the lock order and startup journal marking.
The hub still rejects a signed ticket found only in the synced season list, although a successful sync should make that list available for decisions. After the start file changes in place, /tickets serves its new bytes while scans still use the loaded list; both should use the same snapshot. Growing or shrinking the file during a /tickets reply changes the bytes sent, and a short reply is counted as 200; the reply should contain the loaded list and be counted accurately.
The hub synced a list it never used for decisions, while /tickets reread the start file on every request. A header-time ETag could leave the hub on an old list behind repeated 304 replies. The hub now syncs /season.txt, checks the installed body before conditional requests, and switches decisions and /tickets together using a reference-counted snapshot. It carries used admissions and recorded offline reports across a switch. Here verified means the downloaded file SHA-256 matches the confirmed ETag, the whole list loads under the start-file rules, and the file and its directory have been synced.
|
Ingrid Larsen · reviewer Can an offline report arriving during list preparation lose its used flag? 准备新票单时到达的离线报告,会不会丢掉已用标记? |
|
Ben Carter · author No. The switch copies the reported barcodes before taking 不会。切换前先复制已报告的条码,再拿 |
|
Wang Hao · reviewer What does a sync 现在面板上的同步 |
|
Ben Carter · author An installed list. A round counts as success only if, at its end, hub decisions use the data centre's current list, whether installed from a 200 or confirmed by a 304. Download, HTTP, validation and installation failures count as 是装上。只有这一轮结束时 hub 的判断用的是数据中心当前的票单,才算成功,不管是 200 后新装的,还是 304 确认的。下载、HTTP、校验和安装失败都记为 |
Why
The hub synced a data-centre list it never used for decisions, while
/ticketsreread the start file on every request, so the served bytes could differ from the list behind scan decisions or change mid-reply. A saved ETag could also keep the hub on an old list behind repeated 304 replies.What changed
store_lockafterreports_record, instead of inside the report store, and document the lock order.test_hub_season_reload.py,test_hub_served_list.pyandtest_hub_tickets_send_change.py, with shared helpers intests/hub_ticket_support.py./season.txtinto/tmp/gatepost-season.txt. A list is installed only if its SHA-256 matches the confirmed ETag, it loads under the start-file rules and holds at least one ticket; a rejected list leaves the current one in place and is logged asevent=season_list state=rejected. The new store, decisions and/ticketsswitch together through a reference-counted in-memory snapshot (gate-hub/season.h), carrying used marks and recorded offline reports across the switch.hub_sync_oncesendsIf-None-Matchonly when the installed body still matches the saved ETag (test_hub_sync_stale_etag.py)./ticketsserves the snapshot, with ETag and length taken from it.gatepost_ticket_list_age_secondsnow counts from installation, andgatepost_dc_sync_attempts_total{outcome="success"}means hub decisions use the data centre's current list at the end of the round.test_hub_season_report_switch.py(a report arriving during a switch keeps its ticket used) andtest_hub_season_fsync.py(the install is logged only after the file and directory fsyncs and the rename); adapttest_gate_list_version.py,test_hub_tls.pyandtest_sync_metrics.pyto the season sync.How to verify
On Linux with the build dependencies listed in
Dockerfile.build, run from the repository root:cmake --preset debug cmake --build --preset debug ctest --preset debug -R '^(hub_season_reload|hub_served_list|hub_tickets_send_change|hub_season_report_switch|hub_season_fsync|hub_sync_stale_etag|gate_list_version|sync_metrics|hub_tls|offline_reports)$' --output-on-failurehub_season_fsyncis registered on Linux only. A ticket that exists only in the synced season list must be accepted without restarting the hub, once only, while used marks from the start list are kept and/ticketsserves the season list. Hub decisions still do not check per-ticket signatures; gates do.背景
hub 同步了数据中心的票单,却从不拿它做判断;
/tickets又在每次请求时重读启动文件,提供的字节可能和扫描判断所用的票单不一样,甚至在回复途中发生变化。保存下来的 ETag 还可能让 hub 在一次次 304 响应后一直停留在旧票单上。改动
reports_record返回之后,由 hub 在store_lock下标记对应门票已用,不再在报告存储内部标记;同时写明锁的顺序。test_hub_season_reload.py、test_hub_served_list.py、test_hub_tickets_send_change.py,共用的辅助代码在tests/hub_ticket_support.py。/season.txt同步到/tmp/gatepost-season.txt。只有 SHA-256 与确认过的 ETag 一致、能按启动文件的规则加载、且至少有一张票的票单才会安装;不合格的票单不替换现有票单,并记录event=season_list state=rejected。新的票单库、入场判断和/tickets通过一个带引用计数的内存快照(gate-hub/season.h)一起切换,已用标记和已记录的离线报告都会带过去。hub_sync_once只有在已安装的内容仍与保存的 ETag 相符时才发送If-None-Match(test_hub_sync_stale_etag.py)。/tickets直接提供快照,ETag 和长度都取自快照。gatepost_ticket_list_age_seconds改为从安装时刻算起;gatepost_dc_sync_attempts_total{outcome="success"}表示这一轮结束时,hub 的判断用的是数据中心当前的票单。test_hub_season_report_switch.py(切换期间到达的报告仍让门票保持已用)和test_hub_season_fsync.py(文件和目录都 fsync、完成改名之后才记录安装);test_gate_list_version.py、test_hub_tls.py和test_sync_metrics.py改用赛季同步。怎么验证
在 Linux 环境安装
Dockerfile.build列出的构建依赖后,从仓库根目录运行:cmake --preset debug cmake --build --preset debug ctest --preset debug -R '^(hub_season_reload|hub_served_list|hub_tickets_send_change|hub_season_report_switch|hub_season_fsync|hub_sync_stale_etag|gate_list_version|sync_metrics|hub_tls|offline_reports)$' --output-on-failurehub_season_fsync只在 Linux 上注册。只存在于同步后赛季票单中的门票,无需重启 hub 就应放行且只放行一次;启动票单里的已用标记要保留,/tickets要提供赛季票单。hub 的判断仍不核验每张票的签名,这由闸机负责。