fix(comm): key site liveness on central receive time; gRPC connect timeout + connect-phase deadline failover (COMM-4, COMM-5, WP4 task 4.4)
This commit is contained in:
@@ -271,11 +271,17 @@ Three layers of dead-client detection prevent orphan streams on site nodes:
|
||||
Keepalive settings are configurable via `CommunicationOptions`:
|
||||
- `GrpcKeepAlivePingDelay`: 15 seconds (default)
|
||||
- `GrpcKeepAlivePingTimeout`: 10 seconds (default)
|
||||
- `GrpcConnectTimeout`: 5 seconds (default, validated positive) — `SocketsHttpHandler.ConnectTimeout` on every cross-cluster channel (central→site command pair, site→central control pair, site stream clients). See *Black-holed peers* below.
|
||||
- `GrpcMaxStreamLifetime`: 4 hours (default)
|
||||
- `GrpcMaxConcurrentStreams`: 100 (default)
|
||||
- `GrpcStreamBatchMaxEvents`: 100 (default) — see Event Batching above
|
||||
- `GrpcStreamBatchWindow`: 25 ms (default) — see Event Batching above
|
||||
|
||||
**Black-holed peers (COMM-5, 2026-12).** A peer whose host silently drops SYNs (powered off behind a router, firewall drop, WAN black hole) used to hold every connect for the OS TCP timeout (~21 s on Windows, ~2 min on Linux), so calls with shorter deadlines ended `DeadlineExceeded` — which neither channel pair failed over on — and a dead node kept every command. Three changes close it:
|
||||
- `GrpcConnectTimeout` (5 s) makes the connect fail as `Unavailable` ("Error connecting to subchannel.", `TimeoutException` cause) well inside every call deadline. That shape is also recognised by `GrpcRetrySafety.WasNeverSent`, so even a mutation fails over within the call — the request provably never left the client.
|
||||
- A `DeadlineExceeded` that expires while the channel is still `Connecting`/`TransientFailure` (`GrpcRetrySafety.IsConnectPhaseDeadline`) moves the pair: `SitePairChannelProvider` flips NodeA↔NodeB, `GrpcCentralTransport` flips central-a↔central-b (heartbeat included, so a quiet site leaves a dead central). The deadline is spent, so the call itself is not retried; a deadline on a connected (`Ready`) channel is a slow peer and moves nothing.
|
||||
- The Alarm Summary aggregator's stream **open deadline** is now a stream error (flip node, spend a retry) rather than only a release of the in-flight guard; before, the next reconcile tick reopened on the same black-holed node indefinitely.
|
||||
|
||||
### 6a. Debug Snapshot (Central → Site)
|
||||
- **Pattern**: Request/Response (one-shot, no subscription).
|
||||
- Central sends a `DebugSnapshotRequest` (identified by instance unique name) to the site.
|
||||
|
||||
@@ -51,7 +51,7 @@ Site clusters (metric collection and reporting). Central cluster (aggregation an
|
||||
- **The sequence number is wall-clock anchored on every report** (COMM-1, 2026-12): each report takes `max(previous + 1, now as Unix-ms)`, so after a failover the newly active node's first report sorts above anything the old active node sent, however long either process has run. (The earlier scheme seeded Unix-ms once at process start and added 1 per report; for a pair started `g` ms apart it broke once the active node had sent more than `g` reports — ~42 h for a 5 s gap — after which every report from the new active node was rejected for days.) The same rule drives the central self-report (`$central`).
|
||||
- **A rejected report is nacked, never silently dropped**: `ICentralHealthAggregator.ProcessReport` returns whether it applied the report, and the central communication actor acks the site with `Accepted=false` + an error on a stale rejection. The site's transport then throws, the per-interval counters are restored into the next report, and the drop is logged at the site.
|
||||
- Central tracks two **distinct** signals per site — do not conflate them:
|
||||
- **Liveness (online/offline)**: driven by the **last signal of any kind** (a full report *or* a transport heartbeat, the latter arriving every ~5s from any reachable site node). If central receives no signal within `OfflineTimeout` (default: **60 seconds**), the site is marked **offline**. Because heartbeats are frequent, this only fires on genuine total loss of contact — not during a single-node failover, when the surviving node keeps heartbeating. The synthetic *central* self-report site has no heartbeat source and uses the longer `CentralOfflineTimeout` (default: **3 minutes**) so a single missed self-report does not flap it offline.
|
||||
- **Liveness (online/offline)**: driven by the **last signal of any kind** (a full report *or* a transport heartbeat, the latter arriving every ~5s from any reachable site node). Both are stamped with **central's receive time** — never the site-stamped heartbeat timestamp (COMM-4): the offline check compares against central's clock, so a site clock running X fast used to stretch the timeout to 60 s + X. `MarkHeartbeat` also clamps any future-dated value to central's now. If central receives no signal within `OfflineTimeout` (default: **60 seconds**), the site is marked **offline**. Because heartbeats are frequent, this only fires on genuine total loss of contact — not during a single-node failover, when the surviving node keeps heartbeating. The synthetic *central* self-report site has no heartbeat source and uses the longer `CentralOfflineTimeout` (default: **3 minutes**) so a single missed self-report does not flap it offline.
|
||||
- **Metrics staleness**: an **online** site (heartbeats still arriving) that has produced no full **report** within `MetricsStaleTimeout` (default: **2 minutes**) is flagged **metrics stale**. This surfaces the failure mode where a site's report pipeline (`HealthReportSender`) has died but the node is otherwise reachable — previously such a site showed "online with frozen metrics forever". A site that has **never** delivered a report is anchored on its first-contact time (`FirstSeenAt`), so a report pipeline dead from first boot is also flagged after `MetricsStaleTimeout` (previously such a site showed online-with-no-metrics indefinitely). `MetricsStaleTimeout` must be positive and no shorter than the report interval.
|
||||
- **Online recovery**: when central receives a health report from a site that was marked offline, the site is automatically marked **online** and the metrics-stale flag cleared (a fresh report proves the pipeline is alive); a heartbeat alone also restores **online** but leaves the metrics-stale flag untouched. No manual acknowledgment required.
|
||||
- **Status-transition timestamp**: each online↔offline flip stamps `LastStatusChangeAt`, so the UI can answer "since when has this site been offline/online" rather than only "is it offline now". Report/heartbeat traffic that leaves the status unchanged does not move it.
|
||||
|
||||
Reference in New Issue
Block a user