Skip to content

Remove sync request on edge customer id update - #238

Open
AndriiLandiak wants to merge 1 commit into
masterfrom
fix/remove-sync-on-customer-id-update
Open

Remove sync request on edge customer id update#238
AndriiLandiak wants to merge 1 commit into
masterfrom
fix/remove-sync-on-customer-id-update

Conversation

@AndriiLandiak

Copy link
Copy Markdown
Member

Problem

On every EdgeConfiguration downlink the edge compares its customer id and, if it changed, requests a full sync from the cloud:

boolean edgeCustomerIdUpdated = updateCustomerIdIfRequired(downlinkMsg);
...
if (downlinkMsg.hasEdgeConfiguration()) {
    if (edgeCustomerIdUpdated && !edgeInfo.isSyncInProgress()) {
        log.info("Edge customer id has been updated. Sending sync request...");
        requestSyncToCloud();
    }
}

That request is both redundant and harmful.

Redundant

Assigning or unassigning an edge already emits its own edge event. EdgeEntityProcessor.convertEdgeEventToDownlink turns it into the config downlink:

case ASSIGNED_TO_CUSTOMER, UNASSIGNED_FROM_CUSTOMER -> {
    Edge edge = edgeCtx.getEdgeService().findEdgeById(edgeEvent.getTenantId(), edgeId);
    if (edge != null) {
        return DownlinkMsg.newBuilder()
                .setDownlinkMsgId(EdgeUtils.nextPositiveInt())
                .setEdgeConfiguration(EdgeMsgConstructorUtils.constructEdgeConfiguration(edge))
                .build();
    }
}

So the edge is already told about the new owner. The sync re-fetches every entity type to arrive at the same state.

Harmful

That config downlink is the last message of the assignment flow, and reacting to it with a sync cancels the delivery of that very flow:

  1. Cloud queues the assignment's edge events
  2. Cloud queues the EdgeConfiguration announcing the new owner - last in line
  3. Edge sees the changed customer id and requests a sync
  4. Cloud startSyncProcess -> interruptGeneralProcessingOnSync() -> stopCurrentSendDownlinkMsgsTask(true):
    state.getSendDownlinkMsgsFuture().set(isInterrupted);
    state.getScheduledSendDownlinkTask().cancel(true);
  5. Edge simultaneously gates its own uplinks on isInitialized() && !isSyncInProgress()

Both directions stall until the sync completes, and anything that was in flight when cancel(true) fired waits for the re-sync instead of arriving.

Change

Remove the sync request. Keep the setOrUpdateCustomerId call: BaseEdgeConfigurationHandler is the only writer of edgeInfo.customerId, and that value is passed into every processDownlinkMsg(...). Dropping the call entirely would leave the edge processing downlinks against a stale customer id.

Why now

The trigger has been dormant for months. onConfigurationUpdate used to compare the edge against itself:

this.edge = edge;
if (!this.edge.getOwnerId().equals(edge.getOwnerId())) {  // same reference - always false
    return;
}

Because it never returned early, EdgeUpdateMsg was always sent; its edge-side handler pre-updated the customer id, so setOrUpdateCustomerId later returned false and no sync fired. That guard is now correct (stateCustomerId captured before state.setEdge(edge)), which suppressed the duplicate and exposed the trigger.

Verification

Verified on the PE counterpart, where the same code lives (this file is byte-identical between thingsboard-edge and thingsboard-edge-pe below the license header). Built cloud and edge images locally and ran the full black-box suite:

Tests run: 82, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Log signature across 25 ownership changes:

"Edge customer id has been updated"  : 0    <- trigger gone
"Sync process started"               : 1    <- only the initial connect sync

One sync instead of 26, and the edge still observed every ownership transition (40 config messages alternating between customer-owned and tenant-owned) with entity access granted and revoked correctly.

CE is affected less severely than PE because CE's doSync walks a fixed fetcher list, while PE's grows the cursor by two fetchers per entity group - but the redundant blocking sync is the same on both.

Downstream

thingsboard-edge-pe PRs #121 (master) and #122 (lts-4.3) carry the same change; they will be reconciled with this one so PE takes it via the normal CE merge.

@AndriiLandiak
AndriiLandiak force-pushed the fix/remove-sync-on-customer-id-update branch from cdfe52c to a0770fb Compare August 18, 2026 14:44
@AndriiLandiak
AndriiLandiak force-pushed the fix/remove-sync-on-customer-id-update branch from a0770fb to ae4a136 Compare August 18, 2026 15:16
@AndriiLandiak
AndriiLandiak force-pushed the fix/remove-sync-on-customer-id-update branch from ae4a136 to 08c0797 Compare August 18, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant