Skip to content

Commit 5c095d4

Browse files
sshaderConvex, Inc.
authored andcommitted
Fix check for local backend running (#33355)
The previous code was not actually failing when we exhausted the time limit for checking if a backend was running. I also tried to improve some of the error messaging around the binary failing to run at all by checking that `--help` works first before spawning the main process. GitOrigin-RevId: 7fad056e1f8c7637d91aea687d924047c558b47f
1 parent 31d9f56 commit 5c095d4

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

npm-packages/convex/src/cli/lib/localDeployment/run.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,40 @@ export async function runLocalBackend(
209209
path.join(deploymentDir, "convex_local_storage"),
210210
path.join(deploymentDir, "convex_local_backend.sqlite3"),
211211
];
212+
213+
// Check that binary works by running with --help
214+
try {
215+
const result = child_process.spawnSync(args.binaryPath, [
216+
...commandArgs,
217+
"--help",
218+
]);
219+
if (result.status === 3221225781) {
220+
const message =
221+
"Local backend exited because shared libraries are missing. These may include libraries installed via 'Microsoft Visual C++ Redistributable for Visual Studio.'";
222+
return ctx.crash({
223+
exitCode: 1,
224+
errorType: "fatal",
225+
printedMessage: message,
226+
errForSentry: message,
227+
});
228+
} else if (result.status !== 0) {
229+
const message = `Failed to run backend binary, exit code ${result.status}, error: ${result.stderr.toString()}`;
230+
return ctx.crash({
231+
exitCode: 1,
232+
errorType: "fatal",
233+
printedMessage: message,
234+
errForSentry: message,
235+
});
236+
}
237+
} catch (e) {
238+
const message = `Failed to run backend binary: ${(e as any).toString()}`;
239+
return ctx.crash({
240+
exitCode: 1,
241+
errorType: "fatal",
242+
printedMessage: message,
243+
errForSentry: message,
244+
});
245+
}
212246
const commandStr = `${args.binaryPath} ${commandArgs.join(" ")}`;
213247
logVerbose(ctx, `Starting local backend: \`${commandStr}\``);
214248
const p = child_process
@@ -224,13 +258,6 @@ export async function runLocalBackend(
224258
ctx,
225259
`Local backend exited with code ${code}, full command \`${commandStr}\``,
226260
);
227-
// STATUS_DLL_NOT_FOUND
228-
if (code === 3221225781) {
229-
logVerbose(
230-
ctx,
231-
"Local backend exited because shared libraries are missing. These may include libraries installed via 'Microsoft Visual C++ Redistributable for Visual Studio.'",
232-
);
233-
}
234261
});
235262
const cleanupHandle = ctx.registerCleanup(async () => {
236263
logVerbose(ctx, `Stopping local backend on port ${ports.cloud}`);
@@ -273,8 +300,10 @@ export async function ensureBackendRunning(
273300
errorType: "fatal",
274301
printedMessage: `A different local backend ${text} is running on selected port ${args.cloudPort}`,
275302
});
303+
} else {
304+
// The backend is running!
305+
return;
276306
}
277-
break;
278307
} else {
279308
await new Promise((resolve) => setTimeout(resolve, 500));
280309
timeElapsedSecs += 0.5;
@@ -284,6 +313,12 @@ export async function ensureBackendRunning(
284313
timeElapsedSecs += 0.5;
285314
}
286315
}
316+
const message = `Local backend did not start on port ${args.cloudPort} within ${args.maxTimeSecs} seconds.`;
317+
return await ctx.crash({
318+
exitCode: 1,
319+
errorType: "fatal",
320+
printedMessage: message,
321+
});
287322
}
288323

289324
export async function ensureBackendStopped(

npm-packages/convex/src/cli/lib/localDeployment/upgrade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async function handleUpgrade(
175175
});
176176
}
177177
await downloadSnapshotExport(ctx, {
178-
snapshotExportTs: snaphsotExportState.complete_ts,
178+
snapshotExportTs: snaphsotExportState.start_ts,
179179
inputPath: exportPath,
180180
adminKey: args.adminKey,
181181
deploymentUrl,

0 commit comments

Comments
 (0)