Skip to content

Commit 037c5f1

Browse files
committed
fix: subscribe to org store before checking sync status in syncOrganizationMeta
Mirrors the subscribe-first pattern established in #1600 af06a65 (for governance sync) and 6d41b71 (for reconcileOrganization). Without subscribe-first, the getDataLayerStoreSyncStatus pre-check added to syncOrganizationMeta has a permanent-skip-loop failure mode: if the DataLayer node has no record of an org store (e.g. after a DataLayer DB reset), the status check returns falsy, the loop iteration skips the org, and no subsequent run ever subscribes — the org's metadata stops syncing forever. Also adds a falsy-return guard on subscribeToStoreOnDataLayer: the wrapper in src/datalayer/persistance.js returns false (without throwing) on the common failure paths (no storeId, getSubscriptions RPC failure). Without the falsy check, a datalayer-unreachable failure would slip past the try/catch and produce a misleading "not yet synced" log. Applies to both V1 Organization.syncOrganizationMeta and V2 OrganizationsV2.syncOrganizationMeta.
1 parent 9be287e commit 037c5f1

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/models/organizations/organizations.model.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,31 @@ class Organization extends Model {
13581358

13591359
for (const organization of allSubscribedOrganizations) {
13601360
if (!USE_SIMULATOR) {
1361+
// Subscribe-first, then check sync status. Without subscribing,
1362+
// getDataLayerStoreSyncStatus errors/returns falsy for any store
1363+
// the DL node has no record of (e.g. after a datalayer DB reset),
1364+
// we skip, and no subsequent run ever subscribes — a permanent
1365+
// skip loop. subscribeToStoreOnDataLayer returns falsy on the
1366+
// common failure paths (datalayer unreachable, getSubscriptions
1367+
// RPC failure) and also throws on unexpected errors, so guard on
1368+
// both. Same pattern as Governance.sync and reconcileOrganization.
1369+
try {
1370+
const subscribed = await datalayer.subscribeToStoreOnDataLayer(
1371+
organization.orgUid,
1372+
);
1373+
if (!subscribed) {
1374+
logger.warn(
1375+
`[v1]: syncOrganizationMeta: could not subscribe to org store ${organization.orgUid}. Skipping this run.`,
1376+
);
1377+
continue;
1378+
}
1379+
} catch (error) {
1380+
logger.warn(
1381+
`[v1]: syncOrganizationMeta: could not subscribe to org store ${organization.orgUid}: ${error.message}. Skipping this run.`,
1382+
);
1383+
continue;
1384+
}
1385+
13611386
try {
13621387
const syncStatus = await getDataLayerStoreSyncStatus(organization.orgUid);
13631388
if (!isDlStoreSynced(syncStatus?.sync_status)) {

src/models/v2/organizations-v2.model.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,31 @@ class OrganizationsV2 extends Model {
20862086

20872087
for (const organization of allSubscribedOrganizations) {
20882088
if (!USE_SIMULATOR) {
2089+
// Subscribe-first, then check sync status. Without subscribing,
2090+
// getDataLayerStoreSyncStatus errors/returns falsy for any store
2091+
// the DL node has no record of (e.g. after a datalayer DB reset),
2092+
// we skip, and no subsequent run ever subscribes — a permanent
2093+
// skip loop. subscribeToStoreOnDataLayer returns falsy on the
2094+
// common failure paths (datalayer unreachable, getSubscriptions
2095+
// RPC failure) and also throws on unexpected errors, so guard on
2096+
// both. Same pattern as GovernanceV2.sync and reconcileOrganization.
2097+
try {
2098+
const subscribed = await datalayer.subscribeToStoreOnDataLayer(
2099+
organization.org_uid,
2100+
);
2101+
if (!subscribed) {
2102+
loggerV2.warn(
2103+
`[v2]: syncOrganizationMeta: could not subscribe to org store ${organization.org_uid}. Skipping this run.`,
2104+
);
2105+
continue;
2106+
}
2107+
} catch (error) {
2108+
loggerV2.warn(
2109+
`[v2]: syncOrganizationMeta: could not subscribe to org store ${organization.org_uid}: ${error.message}. Skipping this run.`,
2110+
);
2111+
continue;
2112+
}
2113+
20892114
try {
20902115
const syncStatus = await datalayer.getDataLayerStoreSyncStatus(organization.org_uid);
20912116
if (!isDlStoreSynced(syncStatus?.sync_status)) {

0 commit comments

Comments
 (0)