Skip to content

Only allow a single startProxyServer call at a time - #1313

Merged
fredrikekelund merged 3 commits into
trunkfrom
f26d/initialize-proxy-server-sequentially
May 2, 2025
Merged

Only allow a single startProxyServer call at a time#1313
fredrikekelund merged 3 commits into
trunkfrom
f26d/initialize-proxy-server-sequentially

Conversation

@fredrikekelund

@fredrikekelund fredrikekelund commented May 2, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

startProxyServer is called in SiteServer::start. It's called every time a server with a custom domain config starts and returns early if the proxy server is already initiated.

This can become an issue when the Studio app starts, because Studio will re-initiate the servers that were running when the app quit, and if there were multiple servers with custom domain configs, there will be multiple startProxyServer calls in rapid succession. This leads to errors like this:

This PR fixes the problem by adding a sequential helper in src/lib/proxy-server.ts that makes it so startProxyServer calls are executed sequentially.

Testing Instructions

  1. Apply the following diff
diff --git a/src/lib/proxy-server.ts b/src/lib/proxy-server.ts
index bf861da9..1efd425c 100644
--- a/src/lib/proxy-server.ts
+++ b/src/lib/proxy-server.ts
@@ -145,6 +145,7 @@ export async function checkIfPortIsFree( port: number ): Promise< boolean > {
  * This requires admin/root privileges
  */
 export const startProxyServer = sequential( async (): Promise< boolean > => {
+       console.log( 'startProxyServer' );
        try {
                // Start HTTP server if not already running
                if ( ! isHttpProxyRunning ) {
@@ -227,6 +228,8 @@ export const startProxyServer = sequential( async (): Promise< boolean > => {
                console.error( 'Failed to start proxy servers:', error );
 
                throw new Error( 'PROXY_ERROR_START_FAILED' );
+       } finally {
+               console.log( 'startProxyServer done' );
        }
 } );
  1. Run npm start
  2. Ensure that you have at least three sites with custom domains
  3. Ensure that those sites are all started
  4. Quit the app
  5. Run npm start
  6. Ensure that the app starts without any warnings
  7. Looking at the terminal logs, ensure that the startProxyServer calls were executed sequentially (by looking at the output from the console.log calls you added)

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@fredrikekelund
fredrikekelund requested review from a team and gavande1 May 2, 2025 09:15
@fredrikekelund fredrikekelund self-assigned this May 2, 2025

@gavande1 gavande1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix, @fredrikekelund. It's working as expected. Applying the patch, the error message wasn't shown.

CleanShot 2025-05-02 at 15 05 34@2x

LTGM 👍

@fredrikekelund
fredrikekelund merged commit 583ba72 into trunk May 2, 2025
@fredrikekelund
fredrikekelund deleted the f26d/initialize-proxy-server-sequentially branch May 2, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants