-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
max_execution_time
reached too early
#12814
Comments
Hi @Muffinman. Can you share a bit more about your setup? What web server + SAPI are you using? Are you using Octane or something similar by any chance? |
Hi @iluuu1994 , I'm running the homebrew compiled php-fpm under nginx. No octane in use, I only have php-redis and imagick extensions installed via pecl, everything else should be out of the box. |
That's odd. macOS should use (AFAIK) |
I've only seen it on MacOS. One other thing I've noticed is that if I replace the call to There must be something deep in that code which is causing PHP either to throw the wrong exception, or otherwise somehow miscount it's execution time. |
Unfortunately I don't have a (working) macOS machine to test this. Some minimal reproducer would be great, although I understand this might be tricky. It's also hard to rule out an error in php-redis itself. |
Well I think I've managed to rule out Will keep experimenting to see if I can narrow it down further. |
@Muffinman I've got exactly the same issue, relieved to see it's not just me! Have you been able to find any clues? In my case this affects both PHP Unfortunately it's not easy to debug further on production at the moment, as I've since had to make a short-term workaround to get the page running again. If any more clues come up I can try some specific tests though. Other things I've noticed:
|
Can any of you provide a reproducible codebase? If so, you can send it to me privately over email. If possible without dependencies (databases and whatnot). |
No I didn't manage to track it down unfortunately. In my case I was able to mitigate it by pausing the Model events in Laravel. I think it should be possible to create minimal a reproduction repo. |
@iluuu1994 I'm trying to isolate a reproducible example at the moment, I'll let you know if I manage to get one figured out but it's not straightforward. In my case the error is limited to one specific page, and only occurs for users with lots of associated data. Just seeding a bunch of fake records doesn't seem to cause the problem. However our app does have quite complex nested relationships in user data, so this could be hiding something else. Some more observations from further debugging...
|
@iluuu1994 I've got a reproducible example working 👀 It's very simple to set up:
/**
* Bootstrap any application services.
*/
public function boot(): void
{
while (true) {
// ... do nothing
}
}
Each time I tried this the page would load for somewhere between 20 to 40 seconds, before throwing the error Given the mistimings still occur, despite taking longer than the 1-2 seconds we were noticing with established codebases, perhaps the root cause is compounding throughout the request lifecycle? This was using a clean install of PHP 8.3 via Homebrew on macOS Sonoma 14.1.2, although I noticed a similar issue in production on Ubuntu 18.04.4. Let me know if I can provide any more info. Thanks 🙏 |
@jackwh Thank you for the reproducer! Just to clarify: You are not using I noticed something peculiar. On PHP 8.3(-dev), I get the expected 30 seconds of timeout. 30s is the default value in PHP and has been since basically forever. On PHP 8.2(.13), I get 60 seconds of timeout. However. checking for I can reproduce this with a minimal script: <?php
// var_dump(ini_get('max_execution_time'));
// Reports 30
while (true) {}
// Fails after 60 Changing Since PHP 8.3 actually behaves correctly in my case I'm not sure if this is related. I get consistent 30/60s timeouts, there's no variability. I also tried with |
This was indeed a false lead. The php-cli-server has a bug where |
@iluuu1994 In production we're running nginx with php-fpm, but this could possibly be a red herring. I recall the production timeouts happening "faster than usual", but admittedly I was in a hurry to get a workaround in place, and not paying close attention to how long it took. We've not made any recent code changes, this really did seem to just spring up out of the blue. The fact it's the same page causing timeouts on production and my Mac makes me assume they're linked, but not ruling out something else. Having said that, my test case just used |
@devnexen You have access to a macOS machine, right? Could you see if you can reproduce the issue at hand with the instructions from #12814 (comment)? I had no luck on Linux. Additionally, it would be great if @jackwh could try this reproducer on Linux, e.g. using Laravel Sail. |
I can't reproduce the issue, I get the |
I have also had this on another site, this time a Drupal 10 site - so still quite Symfony heavy but not specific to Laravel.
EDIT: For this site I am able to switch to PHP 8.3.0 to test under that, and I can confirm that I also have the same issue there. Will test some other Drupal sites, should be easy to reproduce if it happens on fresh Drupal installation. |
OK so I went back to basics:
Seems to definitely be shorter the more work the script does, I will try putting some PDO queries in the loop and see if that affects the response time. |
OK so it's definitely socket related. <?php
while (true) {
DB::connection()->select('SHOW TABLES');
} // Timeout in 4.7s <?php
while (true) {
DB::connection()->select('SHOW TABLES');
usleep(100);
} // Timeout in 7.2s <?php
while (true) {
DB::connection()->select('SHOW TABLES');
usleep(500);
} // Timeout in 13.6s <?php
while (true) {
openssl_random_pseudo_bytes(32);
} // Timeout in 19.2s while (true) {
$fh = fsockopen('localhost', 80);
fclose($fh);
} // Timeout in 0.3s!! |
@Muffinman Thank you! I cannot reproduce any of those on Linux. With what method (built-in server, |
These were all run under php-fpm and I was able to reproduce all the way back to php7.4, I didn't try anything earlier. I will re-do these tests with PHP built in server and an FPM docker container and report back. |
I can confirm I get the same timeout behaviour PHP's built-in webserver on native OS. Running under docker ( |
@dunglas Just saw your PR also resolves the issue. Will this be released for 8.2 and 8.3 when merged, because your PR is against |
@windaishi I don't know what's the policy regarding this. Anyway, this patch currently has issues with the curl extension and we're still investigating if relying on libdispatch is the best option. cc @arnaud-lb @devnexen |
I think releasing this on macOS right away is risky. I think the safer bet might be to switch to |
I agree. Before discussing on the list, could everyone confirm that #13567 fixes the issue? Also, do everyone confirm that it's a MacOS 14 + Apple Silicon issue? |
On a dev machine, setting I'm getting Putting in a high value is a workaround in the meantime. |
@Pixelshaped what version of MacOS do you have? Is it fully up to date? Does #13567 fix the issue for you? @Mmaaikel @ejdanderson does 👍 mean that you still have the issue and #13567 fixes it? |
Same issue here, Sonoma, php 8.1 (or 8.2, or 8.3), Symfony project. Error happening in different files from vendor (seems to be random). #13567 didn't work for me |
@Herz3h That's somewhat surprising. How did you test the patch? |
@iluuu1994 I edited the php@8.2 homebrew formula, added patch at the end (patch just adds the OR condition like in the PR: |
I have the same issue, PHP 8.1, 8.2, and 8.3 (via Brew, updated in the past week), no matter what setting for MacBook Pro M1 Pro, Sonoma 14.4.1 |
I have the same issue with PHP 8.1, 8.2, 8.3 using Mamp PRO. The timeout error comes almost immediately. But it doesn't come always. Reloading the page sometimes makes it work, sometimes it throws the error again. Setting I would really appreciate a fix or a workaround, developing is hardly possible now. Do we know if this is only an M1 Pro CPU issue? If it's not present on the M2/M3 etc, I would even replace my laptop. MacBook Pro M1 Pro, Sonoma 14.4.1. |
I have exactly this same issue on M2. Using Mamp PRO. The issue began after upgrading to Sonoma. |
I was able to reproduce the issue on an M2 Pro with latest Sonoma (14.5). This is reproducible in pure C, and appears to be triggered/accelerated by other syscalls: https://gist.github.com/arnaud-lb/012195a2fe4d3a2c1bff530a73ae6b11 Switching to ITIMER_REAL fixes the issue in both PHP and the C reproducer. |
I've sent a message to internals and will merge #13567 if there are no objections. |
@arnaud-lb Did they reply yet? 😅 |
There are no objections so far, so I will merge next week if it continues like that. |
#13567 is now merged in 8.2 and 8.3. |
I was seeing this on macOS and it was very puzzling! Glad to see it fixed in the latest release! |
I've just upgraded PHP to 8.3.9 on M1 and here's what I see when running Psalm:
Never had this issue before. Could this be related? |
Interestingly the error is not thrown when running psalm with |
I'm still seeing the timeout error on my M1 mac, PHP 8.1.29. Was the fix only in 8.2 and 8.3? |
It seems. PHP 8.1 is not actively maintained anymore. I use Homebrew throught https://github.com/shivammathur/homebrew-php which contains a patch for 8.1 |
I started seeing the same issue as @vudaltsov after upgrading from a 8.3.x version (don't remember which) to 8.3.9. |
Should we create a separate issue and a reproducer for this? |
Description
Hi, I'm looking for some guidance in tracking down a very strange error with
max_execution_time
setting not being honoured correctly.We have an incoming JSON POST request to a Laravel backend, which does some processing and stores some data.
The request is a few KB of tree data, and the controller calls a
rebuildTree()
method as below. Internally this makes a lot of calls to the MySQL DB and Redis DB.The problem I'm facing is that this fails every time after 1 second with this error:
I have added some debugging to the exception handler to try to work out why it is doing this:
Now for the next strange part, if I set the
max_execution_time
to some other far larger value, it works!PHP Version
PHP 8.2.13
Operating System
MacOS 14.1.1
The text was updated successfully, but these errors were encountered: