diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsx
index 7f2b0c152a..2e72d1335c 100644
--- a/packages/desktop-client/src/components/manager/ConfigServer.tsx
+++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx
@@ -56,6 +56,10 @@ export function ElectronServerConfig({
const [startingSyncServer, setStartingSyncServer] = useState(false);
const onConfigureSyncServer = async () => {
+ if (startingSyncServer) {
+ return; // Prevent multiple clicks
+ }
+
if (
isNaN(electronServerPort) ||
electronServerPort <= 0 ||
@@ -221,23 +225,23 @@ export function ElectronServerConfig({
>
{!electronSyncServerRunning ? (
-
+
) : (
-
+
)}
diff --git a/packages/sync-server/src/app.ts b/packages/sync-server/src/app.ts
index 427680116f..62db2b8597 100644
--- a/packages/sync-server/src/app.ts
+++ b/packages/sync-server/src/app.ts
@@ -156,6 +156,15 @@ function parseHTTPSConfig(value: string) {
return fs.readFileSync(value);
}
+function sendServerStartedMessage() {
+ // Signify to any parent process that the server has started. Used in electron desktop app
+ // @ts-ignore-error electron types
+ process.parentPort?.postMessage({ type: 'server-started' });
+ console.log(
+ 'Listening on ' + config.get('hostname') + ':' + config.get('port') + '...',
+ );
+}
+
export async function run() {
const portVal = config.get('port');
const port = typeof portVal === 'string' ? parseInt(portVal) : portVal;
@@ -186,16 +195,12 @@ export async function run() {
key: parseHTTPSConfig(config.get('https.key')),
cert: parseHTTPSConfig(config.get('https.cert')),
};
- https.createServer(httpsOptions, app).listen(port, hostname);
+ https.createServer(httpsOptions, app).listen(port, hostname, () => {
+ sendServerStartedMessage();
+ });
} else {
- app.listen(port, hostname);
+ app.listen(port, hostname, () => {
+ sendServerStartedMessage();
+ });
}
-
- // Signify to any parent process that the server has started. Used in electron desktop app
- // @ts-ignore-error electron types
- process.parentPort?.postMessage({ type: 'server-started' });
-
- console.log(
- 'Listening on ' + config.get('hostname') + ':' + config.get('port') + '...',
- );
}
diff --git a/upcoming-release-notes/5303.md b/upcoming-release-notes/5303.md
new file mode 100644
index 0000000000..77d6771c7b
--- /dev/null
+++ b/upcoming-release-notes/5303.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [MikesGlitch]
+---
+
+Fix server-started message invoking too early, causing desktop app server configuration flakiness.