Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/cli/php-server-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,17 @@ async function startServer( config: ServerConfig, signal: AbortSignal ): Promise
} );
} );

stopSignal.throwIfAborted();
await waitForServerReady( `http://localhost:${ config.port }/`, stopSignal );

serverChild.once( 'exit', ( code, signalName ) => {
errorToConsole(
`PHP child process exited unexpectedly (code: ${ code }, signal: ${ signalName })`
);
process.exit( code ?? 1 );
} );

stopSignal.throwIfAborted();
await waitForServerReady( `http://localhost:${ config.port }/`, stopSignal );
await installWordPress( config, phpVersion, stopSignal );

phpProcess = serverChild;
} catch ( error ) {
if ( spawnedChild && ! spawnedChild.killed ) {
Expand Down
31 changes: 25 additions & 6 deletions apps/cli/process-manager-daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export class ProcessManagerDaemon {
env,
stdio: [ 'ignore', 'pipe', 'pipe', 'ipc' ],
windowsHide: true,
detached: process.platform !== 'win32',
} );

const managedProcess: ManagedProcessRunning = {
Expand Down Expand Up @@ -293,7 +294,7 @@ export class ProcessManagerDaemon {

await new Promise< void >( ( resolve ) => {
const timeoutId = setTimeout( () => {
managedProcess.child.kill( 'SIGKILL' );
this.forceCleanupChild( managedProcess );
}, STOP_TIMEOUT_MS );

managedProcess.child.once( 'exit', () => {
Expand Down Expand Up @@ -418,11 +419,28 @@ export class ProcessManagerDaemon {
if ( managedProcess.settled ) {
continue;
}
this.forceCleanupChild( managedProcess );
}
}

private forceCleanupChild( managedProcess: ManagedProcess ) {
if ( process.platform === 'win32' ) {
try {
managedProcess.child.kill( 'SIGKILL' );
managedProcess.child.kill( 'SIGTERM' );
} catch {
// Do nothing
}
return;
}

if ( ! managedProcess.child.pid ) {
return;
}

try {
process.kill( -managedProcess.child.pid, 'SIGKILL' );
} catch {
// Do nothing
}
}

Expand All @@ -432,17 +450,18 @@ export class ProcessManagerDaemon {
}

this.shuttingDown = true;
await this.broadcastEvent( {
type: 'daemon-kill',
payload: { reason },
} );

await Promise.allSettled(
Array.from( this.managedProcesses.values() ).map( ( managedProcess ) =>
this.stopProcess( managedProcess.name )
)
);

await this.broadcastEvent( {
type: 'daemon-kill',
payload: { reason },
} );

await new Promise< void >( ( resolve ) => {
void this.controlServer.close().then( () => resolve() );
} );
Expand Down
5 changes: 5 additions & 0 deletions apps/studio/src/ipc-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { setSentryWpcomUserIdMain } from 'src/lib/main-sentry-utils';
import * as oauthClient from 'src/lib/oauth';
import { getAiInstructionsPath } from 'src/lib/server-files-paths';
import { shellOpenExternalWrapper } from 'src/lib/shell-open-external-wrapper';
import { updateSiteUrl } from 'src/lib/update-site-url';
import * as windowsHelpers from 'src/lib/windows-helpers';
import { getLogsFilePath, writeLogToFile, type LogLevel } from 'src/logging';
import { getMainWindow } from 'src/main-window';
Expand Down Expand Up @@ -1053,6 +1054,10 @@ export async function copySite(
noStart: true,
} );

// Playground sets the correct siteurl internally, but for the native-php runtime, we need to
// explicitly update that option
await updateSiteUrl( server, `http://localhost:${ details.port }` );
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.

Should we run this only for native-php?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's obviously not required for Playground, but that's only because Playground enforces the siteurl internally. I think it makes sense to follow the more standard approach of explicitly updating the siteurl rather than relying on some runtimes to do it for us.


// Persist themeDetails to appdata (Studio-only data)
if ( sourceSite.themeDetails ) {
server.details.themeDetails = sourceSite.themeDetails;
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/src/modules/cli/lib/execute-export-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function executeExportCliCommand(
const { abortSignal } = options;

function abortExportProcess() {
childProcess.kill( 'SIGKILL' );
childProcess.kill( 'SIGTERM' );
emitFailure( new Error( 'Export aborted' ) );
}

Expand Down
Loading