Skip to content

Commit 2b23702

Browse files
add workaround for race condition when reprovisioning
1 parent cc201e8 commit 2b23702

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

cli/src/api/BaseDeployCommand.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ export default abstract class BaseDeployCommand extends CloudInstanceCommand {
136136
timeoutMs: deployTimeoutMs
137137
});
138138

139+
/**
140+
* We typically want to perform a sync config validation after a (re)provision.
141+
* Even though we wait for the deploy operation above, the request to validate sync config
142+
* can still fail due to the error
143+
* [INTERNAL_SERVER_ERROR] Something went wrong
144+
* getaddrinfo ENOTFOUND 69b8fec1358aa0646ff0ce71.powersync.journeyapps.com
145+
* Which indicates that the API runner is not active yet.
146+
* For this reason, we poll the diagnostics API until we get some successful response from the API
147+
*/
148+
for (let retryCount = 0; retryCount < 5; retryCount++) {
149+
try {
150+
const { linked } = this.project;
151+
await this.client.getInstanceDiagnostics({
152+
app_id: linked.project_id,
153+
id: linked.instance_id,
154+
org_id: linked.org_id
155+
});
156+
// We reached the instance
157+
break;
158+
} catch {
159+
if (retryCount === 4) {
160+
throw new Error(
161+
'Failed to reach instance after provision. Please check the instance status and try again.'
162+
);
163+
}
164+
165+
await new Promise<void>((resolve) => {
166+
setTimeout(resolve, 5000);
167+
});
168+
}
169+
}
170+
139171
spinner.stop();
140172
} catch (error) {
141173
spinner.stop();

0 commit comments

Comments
 (0)