Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate PHP runtime on crash so it can continue to satisfy subsequent requests #1453

Closed
brandonpayton opened this issue May 22, 2024 · 3 comments · Fixed by #1628
Closed

Rotate PHP runtime on crash so it can continue to satisfy subsequent requests #1453

brandonpayton opened this issue May 22, 2024 · 3 comments · Fixed by #1628

Comments

@brandonpayton
Copy link
Member

We would like Playground to be more resilient in the face of crashes. We've encountered a variety of memory-related crashes, but this issue was inspired most recently by #1332.

We need to update the rotatePHPRuntime() function to rotate when it detects a crash.

@brandonpayton
Copy link
Member Author

I'm assigning this issue to myself, but feel free to grab it if I haven't started on it yet.

@bgrgicak
Copy link
Collaborator

@brandonpayton would something like this work?
I'm working on a error modal task and wanted to check if rotating the runtime would help me get PHP logs (it didn't).

diff --git a/packages/php-wasm/universal/src/lib/base-php.ts b/packages/php-wasm/universal/src/lib/base-php.ts
index 9f5ff746..b9832903 100644
--- a/packages/php-wasm/universal/src/lib/base-php.ts
+++ b/packages/php-wasm/universal/src/lib/base-php.ts
@@ -31,6 +31,7 @@ import {
 } from '@php-wasm/util';
 import { PHPRequestHandler } from './php-request-handler';
 import { logger } from '@php-wasm/logger';
+import { rotatePHPRuntime } from './rotate-php-runtime';
 
 const STRING = 'string';
 const NUMBER = 'number';
@@ -361,6 +362,14 @@ export abstract class BasePHP implements IsomorphicLocalPHP, Disposable {
                                // Distinguish between PHP request and PHP-wasm errors
                                source: (e as any).source ?? 'php-wasm',
                        });
+                       if (this.requestHandler) {
+                               rotatePHPRuntime({
+                                       php: this,
+                                       cwd: this.requestHandler.documentRoot,
+                                       recreateRuntime: this[__private__dont__use],
+                                       maxRequests: 400,
+                               });
+                       }
                        throw e;
                } finally {
                        try {

@adamziel
Copy link
Collaborator

adamziel commented Jul 1, 2024

This one seems stale so I'll clear the assignee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants