[Bug]: A failed artifact push on reconnect clears the gateway's record of the control plane's artifact ID

Open Beginner friendly
#4,162 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, sqlite
Domain
api, backend

Research direction

Start at gateway/gateway-controller/pkg/controlplane/sync.go:741, where reconnect failures call UpdateCPSyncStatus, and compare with the single-push call at pkg/controlplane/client.go:4730. Check how the stored ID is updated in pkg/storage/sql_store.go:1336. Done when a failed reconnect push preserves the existing control-plane artifact ID; verify with a regression test for that failure path.

Written by the indexing model from the issue text.

Description

Area/Gateway Aspect/Other Severity/Minor Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/Other (Anything else which does not match above categories)

Description

When the gateway reconnects, it re-pushes every artifact it created. If the control plane rejects one of them, the gateway marks it failed and also deletes the control plane's artifact ID it had stored for it. A failed single push (on create or update) keeps the ID; only the reconnect push clears it.

Until a later push succeeds, the gateway can't match control-plane events that name the artifact by its control-plane ID. API keys are one example: getArtifactConfigByID falls back to the stored ID (pkg/utils/api_key.go:1930), and the API-key backfill on connect maps by it (pkg/controlplane/client.go:1126).

Observed

  1. I created a REST API on the gateway with the project-id annotation of an existing project. It was pushed, and the gateway recorded cp_artifact_id.
  2. I updated it on the gateway to the annotation of a project that doesn't exist, so the control plane rejects the push. cp_sync_status became failed, and cp_artifact_id was still set.
  3. I restarted gateway-controller. The reconnect push failed for the same reason, cp_sync_status is failed, and cp_artifact_id is now NULL.

Expected
A failed push leaves the stored control-plane artifact ID unchanged, as the single-push path already does.

Cause
The reconnect push records a failure with an empty ID (gateway/gateway-controller/pkg/controlplane/sync.go:741: UpdateCPSyncStatus(cfg.UUID, "", …)), and UpdateCPSyncStatus writes NULL for an empty ID (pkg/storage/sql_store.go:1336). The single-push path passes the existing ID (pkg/controlplane/client.go:4730: UpdateCPSyncStatus(cfg.UUID, cfg.CPArtifactID, …)). The fix is to pass cfg.CPArtifactID at sync.go:741.

Steps to Reproduce
  1. Create a REST API on a connected gateway with the project-id annotation of an existing project, and wait for it to be pushed.
  2. Update it on the gateway so the control plane rejects the push (for example, an annotation naming a project that doesn't exist).
  3. Restart gateway-controller.
  4. In the gateway's database, the artifact's cp_artifact_id is now NULL.
Severity Level of the Issue

Severity/Minor (Non-critical functionality. Can be fixed in future releases)

Environment Details (with versions)

Current main (0ee943ff4). Platform-api and gateway built from source and run by the IT suite (tests/framework), with the gateway on SQLite, on macOS with Rancher Desktop.

Dominant language
Go
Stars
85
Forks
137
Avg merge
1d 12h
Merged PRs (30d)
247

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.