Skip to content

Commit 9346f2f

Browse files
committed
Merge origin/main into fix/php-inline-html-2000
Signed-off-by: Martin Vogel <[email protected]>
2 parents 460ed14 + 0433142 commit 9346f2f

21 files changed

Lines changed: 1036 additions & 12 deletions

‎.github/workflows/pr-acknowledgement.yml‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,25 @@ jobs:
5151
run: |
5252
set -euo pipefail
5353
MESSAGE_FILE=.github/pr-acknowledgement.md
54+
BODY_FILE="$RUNNER_TEMP/pr-acknowledgement-body.md"
5455
5556
if [ ! -f "$MESSAGE_FILE" ]; then
5657
echo "No $MESSAGE_FILE in the base tree — acknowledgements are off."
5758
exit 0
5859
fi
5960
60-
# An empty or whitespace-only file is the documented off switch.
61-
if [ -z "$(tr -d '[:space:]' < "$MESSAGE_FILE")" ]; then
62-
echo "$MESSAGE_FILE is blank — acknowledgements are off."
61+
# HTML comments in the template are notes for maintainers. Posted
62+
# verbatim they become text a reader cannot see but a tool can, and
63+
# our own PR screening holds every comment that carries hidden text.
64+
# Strip them (an unterminated one runs to the end, as GitHub renders
65+
# it) so the posted body is exactly what the contributor sees.
66+
perl -0777 -pe 's/<!--.*?(?:-->|\z)[ \t]*\n?//gs' "$MESSAGE_FILE" > "$BODY_FILE"
67+
68+
# A body with no visible text is the documented off switch.
69+
if [ -z "$(tr -d '[:space:]' < "$BODY_FILE")" ]; then
70+
echo "$MESSAGE_FILE has no visible text — acknowledgements are off."
6371
exit 0
6472
fi
6573
66-
gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file "$MESSAGE_FILE"
74+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file "$BODY_FILE"
6775
echo "Acknowledged PR #${PR_NUMBER}."

‎install.ps1‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,28 @@ try {
277277

278278
# Validate the zip namespace before extraction. Windows paths are
279279
# case-insensitive, so two entries that differ only in case are ambiguous and
280-
# must never be allowed to overwrite each other. The official five entries are
280+
# must never be allowed to overwrite each other. The official four entries are
281281
# required at the archive root with their exact release names.
282+
#
283+
# Two failure classes are reported differently (both still exit 1; nothing is
284+
# relaxed). An unsafe entry path or a duplicate/case-conflicting entry is a
285+
# hostile archive shape. A well-formed archive whose root file SET differs from
286+
# $WindowsArchiveNames already passed checksum verification above, so it is
287+
# the published artifact for $BaseUrl -- the usual cause is this script being
288+
# newer or older than that release (e.g. install.ps1 run from main ahead of
289+
# the latest release, #1218). Calling that "unsafe" sends the user hunting for
290+
# tampering that is not there. Every entry is screened for the hostile class
291+
# BEFORE any layout verdict, so a bad path can never hide behind a layout
292+
# message just because an unexpected entry happened to come first.
293+
$LayoutMismatch = $false
282294
try {
283295
Add-Type -AssemblyName System.IO.Compression.FileSystem
284296
$zip = [System.IO.Compression.ZipFile]::OpenRead("$TmpDir\$Archive")
285297
try {
286298
$seen = New-Object 'System.Collections.Generic.HashSet[string]' ([System.StringComparer]::OrdinalIgnoreCase)
287299
$archiveCounts = @{}
288300
foreach ($archiveName in $WindowsArchiveNames) { $archiveCounts[$archiveName] = 0 }
301+
$layoutProblem = $null
289302
foreach ($entry in $zip.Entries) {
290303
$entryName = $entry.FullName.Replace('\', '/')
291304
$isDirectory = $entryName.EndsWith('/')
@@ -304,10 +317,16 @@ try {
304317
throw "duplicate or case-conflicting zip entry: $($entry.FullName)"
305318
}
306319
if (-not ($WindowsArchiveNames -ccontains $entryName) -or $isDirectory) {
307-
throw "archive contains an unexpected root entry: $($entry.FullName)"
320+
if ($null -eq $layoutProblem) {
321+
$layoutProblem = "archive contains an unexpected root entry: $($entry.FullName)"
322+
}
323+
continue
308324
}
309325
$archiveCounts[$entryName] = $archiveCounts[$entryName] + 1
310326
}
327+
# Every entry passed the hostile-shape checks; only now judge the layout.
328+
$LayoutMismatch = $true
329+
if ($null -ne $layoutProblem) { throw $layoutProblem }
311330
foreach ($archiveName in $WindowsArchiveNames) {
312331
if ($archiveCounts[$archiveName] -ne 1) {
313332
throw "archive must contain exactly one $archiveName"
@@ -316,11 +335,21 @@ try {
316335
if ($seen.Count -ne $WindowsArchiveNames.Count) {
317336
throw "archive does not match the exact Windows release allowlist"
318337
}
338+
$LayoutMismatch = $false
319339
} finally {
320340
$zip.Dispose()
321341
}
322342
} catch {
323-
Write-Host "error: unsafe or incomplete release archive: $_" -ForegroundColor Red
343+
if ($LayoutMismatch) {
344+
Write-Host "error: release archive layout does not match this installer: $_" -ForegroundColor Red
345+
Write-Host " The archive matched the checksum published with it at $BaseUrl, so it is"
346+
Write-Host " the genuine release artifact, built for a different installer version."
347+
Write-Host " This installer expects: $($WindowsArchiveNames -join ', ')"
348+
Write-Host " Fix: run the install.ps1 shipped inside that same release archive, or"
349+
Write-Host " re-run this script after the next release is published."
350+
} else {
351+
Write-Host "error: unsafe release archive: $_" -ForegroundColor Red
352+
}
324353
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
325354
exit 1
326355
}

‎src/cypher/cypher.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5370,6 +5370,34 @@ static void ret_agg_emit_row(cbm_return_clause_t *ret, ret_agg_entry_t *agg, res
53705370
rb_add_row(rb, row);
53715371
}
53725372

5373+
/* True when every RETURN item is an aggregate, so the whole input is one group. */
5374+
static bool ret_agg_is_ungrouped(const cbm_return_clause_t *ret) {
5375+
for (int ci = 0; ci < ret->count; ci++) {
5376+
if (!is_aggregate_func(ret->items[ci].func)) {
5377+
return false;
5378+
}
5379+
}
5380+
return true;
5381+
}
5382+
5383+
/* The one row an ungrouped aggregation answers when no binding reached it
5384+
* (#2742): count and sum are 0, collect is an empty list, and avg/min/max have
5385+
* no value, rendered as "" like any other null. */
5386+
static void ret_agg_emit_empty_row(cbm_return_clause_t *ret, result_builder_t *rb) {
5387+
const char *row[CBM_SZ_32];
5388+
for (int ci = 0; ci < ret->count && ci < CBM_SZ_32; ci++) {
5389+
const char *func = ret->items[ci].func;
5390+
if (strcmp(func, "COUNT") == 0 || strcmp(func, "SUM") == 0) {
5391+
row[ci] = "0";
5392+
} else if (strcmp(func, "COLLECT") == 0) {
5393+
row[ci] = "[]";
5394+
} else {
5395+
row[ci] = "";
5396+
}
5397+
}
5398+
rb_add_row(rb, row);
5399+
}
5400+
53735401
static void ret_sink_feed_agg(ret_sink_t *s, binding_t *bindings, int bind_count) {
53745402
cbm_return_clause_t *ret = s->ret;
53755403
for (int bi = 0; bi < bind_count && !s->done; bi++) {
@@ -5586,6 +5614,11 @@ static void ret_sink_finish(ret_sink_t *s) {
55865614
for (int a = 0; a < s->agg_count; a++) {
55875615
ret_agg_emit_row(ret, &s->aggs[a], rb);
55885616
}
5617+
/* Without grouping keys the input is a single group even when it is
5618+
* empty; a grouped aggregation over no rows has no group to report. */
5619+
if (s->agg_count == 0 && ret_agg_is_ungrouped(ret)) {
5620+
ret_agg_emit_empty_row(ret, rb);
5621+
}
55895622
}
55905623
ret_sink_free(s);
55915624

‎src/daemon/host.c‎

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ enum {
5252
HOST_HTTP_RETRY_INITIAL_MS = 1000,
5353
HOST_HTTP_RETRY_MAX_MS = 30000,
5454
HOST_WATCH_INTERVAL_MS = 5000,
55+
/* Age-based temp cleaners need days of inactivity (macOS tmp_cleaner: 3);
56+
* a minute bounds the blind window after a long sleep (#2178). */
57+
HOST_COORDINATION_TOUCH_MS = 60000,
5558
HOST_CONFLICT_LOG_CAP = 1024 * 1024,
5659
HOST_OPERATION_LOG_CAP = 5 * 1024 * 1024,
5760
HOST_PATH_CAP = 4096,
@@ -875,10 +878,58 @@ static bool host_background_start(host_state_t *host) {
875878
return true;
876879
}
877880

881+
/* Coordination handles the host retains for the generation's whole lifetime. */
882+
typedef struct {
883+
const cbm_daemon_ipc_endpoint_t *endpoint;
884+
cbm_version_cohort_lease_t *cohort_lease;
885+
cbm_version_cohort_daemon_claim_t *daemon_claim;
886+
cbm_daemon_ipc_participant_guard_t *participant_guard;
887+
} host_coordination_t;
888+
889+
typedef struct {
890+
const char *lost; /* first held file whose path no longer names it */
891+
const char *transient; /* first still-valid file that could not be refreshed */
892+
} host_touch_result_t;
893+
894+
static void host_touch_note(host_touch_result_t *result, const char *file, int status) {
895+
if (status == 0 && !result->lost) {
896+
result->lost = file;
897+
} else if (status < 0 && !result->transient) {
898+
result->transient = file;
899+
}
900+
}
901+
902+
static int host_cohort_touch_status(cbm_version_cohort_status_t status) {
903+
return status == CBM_VERSION_COHORT_OK ? 1 : (status == CBM_VERSION_COHORT_IO ? -1 : 0);
904+
}
905+
906+
/* Refresh every long-held runtime file. A held lock whose path now names
907+
* another inode coordinates nothing: forked index workers read the daemon as
908+
* uncoordinated and a peer can start a second generation (#2178). Every file
909+
* is visited even after one fails so the rest keep being refreshed. */
910+
static host_touch_result_t host_coordination_touch(const host_coordination_t *coordination,
911+
cbm_daemon_runtime_service_t *service) {
912+
host_touch_result_t result = {0};
913+
host_touch_note(&result, "cohort_daemon_claim",
914+
host_cohort_touch_status(
915+
cbm_version_cohort_daemon_claim_touch(coordination->daemon_claim)));
916+
host_touch_note(
917+
&result, "cohort_lease",
918+
host_cohort_touch_status(cbm_version_cohort_lease_touch(coordination->cohort_lease)));
919+
host_touch_note(&result, "participant_guard",
920+
cbm_daemon_ipc_participant_guard_touch(coordination->endpoint,
921+
coordination->participant_guard));
922+
host_touch_note(&result, "listener", cbm_daemon_runtime_service_touch_listener(service));
923+
return result;
924+
}
925+
878926
static bool host_wait_for_lifetime(cbm_daemon_runtime_service_t *service,
879-
atomic_int *stop_requested, host_state_t *host, bool permanent) {
927+
atomic_int *stop_requested, host_state_t *host, bool permanent,
928+
const host_coordination_t *coordination) {
880929
uint64_t initial_deadline = cbm_now_ms() + HOST_INITIAL_CLIENT_TIMEOUT_MS;
881930
uint64_t stopping_deadline = 0;
931+
uint64_t next_touch = 0;
932+
bool touch_degraded = false;
882933
for (;;) {
883934
cbm_daemon_runtime_service_state_t state = cbm_daemon_runtime_service_state(service);
884935
if (state == CBM_DAEMON_RUNTIME_SERVICE_EXITED) {
@@ -910,6 +961,28 @@ static bool host_wait_for_lifetime(cbm_daemon_runtime_service_t *service,
910961
stop ? "stop_requested" : "initial_window_expired");
911962
return cbm_daemon_runtime_service_stop(service, HOST_RUNTIME_SHUTDOWN_MS);
912963
}
964+
/* Permanent generations too: exiting lets the next client start a
965+
* coordinated generation, while re-claiming would race that client. */
966+
if (cbm_now_ms() >= next_touch) {
967+
next_touch = cbm_now_ms() + HOST_COORDINATION_TOUCH_MS;
968+
host_touch_result_t touched = host_coordination_touch(coordination, service);
969+
if (touched.lost) {
970+
cbm_log_warn("daemon.lifetime_end", "reason", "coordination_file_lost", "file",
971+
touched.lost);
972+
return cbm_daemon_runtime_service_stop(service, HOST_RUNTIME_SHUTDOWN_MS);
973+
}
974+
/* A refresh failure on a still-valid file (read-only remount,
975+
* EMFILE) is not loss: keep serving, retry next tick, and log
976+
* only transitions so a persistent condition cannot flood. */
977+
if ((touched.transient != NULL) != touch_degraded) {
978+
touch_degraded = touched.transient != NULL;
979+
if (touch_degraded) {
980+
cbm_log_warn("daemon.coordination_touch_failed", "file", touched.transient);
981+
} else {
982+
cbm_log_info("daemon.coordination_touch_recovered");
983+
}
984+
}
985+
}
913986
host_http_reconcile_at(host, cbm_now_ms(), false);
914987
/* Retire an ephemeral generation that lingered for cold-storm cohort
915988
* participants once they drain, or once its bounded linger elapses.
@@ -919,6 +992,22 @@ static bool host_wait_for_lifetime(cbm_daemon_runtime_service_t *service,
919992
}
920993
}
921994

995+
bool cbm_daemon_host_wait_for_lifetime_for_test(cbm_daemon_runtime_service_t *service,
996+
const cbm_daemon_ipc_endpoint_t *endpoint,
997+
cbm_version_cohort_lease_t *cohort_lease,
998+
cbm_version_cohort_daemon_claim_t *daemon_claim,
999+
cbm_daemon_ipc_participant_guard_t *guard) {
1000+
host_state_t host = {0};
1001+
atomic_int stop_requested = 0;
1002+
host_coordination_t coordination = {
1003+
.endpoint = endpoint,
1004+
.cohort_lease = cohort_lease,
1005+
.daemon_claim = daemon_claim,
1006+
.participant_guard = guard,
1007+
};
1008+
return host_wait_for_lifetime(service, &stop_requested, &host, false, &coordination);
1009+
}
1010+
9221011
static bool host_application_shutdown(host_state_t *host) {
9231012
if (cbm_daemon_application_shutdown(host->application, HOST_APPLICATION_SHUTDOWN_MS)) {
9241013
return true;
@@ -1130,7 +1219,14 @@ int cbm_daemon_host_run(const cbm_daemon_host_config_t *config) {
11301219
: "unavailable",
11311220
"memory_budget_bytes", memory_budget, "physical_job_limit", physical_job_limit,
11321221
"worker_memory_budget_bytes", worker_memory_budget);
1133-
if (!host_wait_for_lifetime(service, config->stop_requested, &host, config->permanent)) {
1222+
host_coordination_t coordination = {
1223+
.endpoint = config->endpoint,
1224+
.cohort_lease = cohort_lease,
1225+
.daemon_claim = daemon_claim,
1226+
.participant_guard = participant_guard,
1227+
};
1228+
if (!host_wait_for_lifetime(service, config->stop_requested, &host, config->permanent,
1229+
&coordination)) {
11341230
host_force_terminate("runtime");
11351231
}
11361232

‎src/daemon/host_internal.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include <stdint.h>
1010

1111
struct cbm_daemon_ipc_endpoint;
12+
struct cbm_daemon_ipc_participant_guard;
13+
struct cbm_daemon_runtime_service;
14+
struct cbm_version_cohort_daemon_claim;
15+
struct cbm_version_cohort_lease;
1216

1317
typedef bool (*cbm_daemon_host_cleanup_release_for_test_fn)(void *context);
1418

@@ -68,4 +72,14 @@ bool cbm_daemon_host_http_reconcile_free_refusal_for_test(
6872
* the failure, the adapter must cancel so the final free succeeds. */
6973
bool cbm_daemon_host_http_thread_create_failure_lifecycle_for_test(void);
7074

75+
/* Run the production lifetime loop over caller-held coordination handles with
76+
* no HTTP host state and no stop request. The generation is ephemeral, so a
77+
* loop that misses a loss still ends at the initial client window instead of
78+
* hanging the test. Returns the loop's own result. */
79+
bool cbm_daemon_host_wait_for_lifetime_for_test(
80+
struct cbm_daemon_runtime_service *service, const struct cbm_daemon_ipc_endpoint *endpoint,
81+
struct cbm_version_cohort_lease *cohort_lease,
82+
struct cbm_version_cohort_daemon_claim *daemon_claim,
83+
struct cbm_daemon_ipc_participant_guard *guard);
84+
7185
#endif /* CBM_DAEMON_HOST_INTERNAL_H */

0 commit comments

Comments
 (0)