Skip to content

Use ITIMER_REAL for timeout handling on Apple Silicon systems #13567

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

Closed

Conversation

windaishi
Copy link
Contributor

This closes #12814

@windaishi windaishi requested a review from nielsdos March 4, 2024 09:28
@windaishi
Copy link
Contributor Author

Can someone explain me, why this PR is failing? I cannot conclude why my change can have impact on openssl_private_decrypt

@devnexen
Copy link
Member

devnexen commented Mar 4, 2024

it does not, don t worry :)

@@ -1522,7 +1522,8 @@ static void zend_set_timeout_ex(zend_long seconds, bool reset_signals) /* {{{ */
t_r.it_value.tv_sec = seconds;
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;

# if defined(__CYGWIN__) || defined(__PASE__)
# if defined(__CYGWIN__) || defined(__PASE__) || (defined(__aarch64__) && defined(__APPLE__))
// ITIMER_PROF is broken in Apple Silicon system with MacOS >= 14
Copy link
Member

Choose a reason for hiding this comment

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

PHP uses tabs, not spaces. (using the refined-github extensin allows to see that kind of issues during code reviews)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I will check this out.

@nielsdos
Copy link
Member

nielsdos commented Mar 4, 2024

It seems @arnaud-lb is looking into this now (#13592)

@arnaud-lb
Copy link
Member

Oh, I wasn't aware of this PR. I will close mine.

@bukka
Copy link
Member

bukka commented Mar 5, 2024

Shouldn't this change also zend_unset_timeout?

@windaishi windaishi requested a review from dstogov as a code owner March 11, 2024 18:23
@windaishi
Copy link
Contributor Author

Sorry for the late reply, had the flue last week.

@windaishi windaishi requested a review from dunglas March 11, 2024 18:24
Comment on lines -1525 to 1530
# if defined(__CYGWIN__) || defined(__PASE__)
# if defined(__CYGWIN__) || defined(__PASE__) || (defined(__aarch64__) && defined(__APPLE__))
// ITIMER_PROF is broken in Apple Silicon system with MacOS >= 14. The SIGPROF signal is sent way too early
// when the process opens sockets.
setitimer(ITIMER_REAL, &t_r, NULL);
}
signo = SIGALRM;
Copy link
Member

Choose a reason for hiding this comment

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

SIGALRM may conflict with sleep(). I don't have Mac and can't check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you have in mind exactly? I can check it on my machine. Do you think sleep is just broken?

Copy link
Member

@dunglas dunglas Mar 27, 2024

Choose a reason for hiding this comment

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

To prevent any conflict, for instance with pcntl_alarm(), you could use SIGIO, as in #13468 (comment).

Copy link
Member

Choose a reason for hiding this comment

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

I meant calls to sleep() may conflict with signal handlers for SIGALARM.
This is the old well known problem. (see man 3 sleep - "On some systems, sleep() may be implemented using alarm(2) and SIGALRM (POSIX.1 permits this); mixing calls to alarm(2) and sleep() is a bad idea.")

I can't check this PR, and I can't take a decision about its acceptance or rejection.

Copy link
Member

Choose a reason for hiding this comment

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

@dstogov according to the MacOS man page, sleep() does not use SIGALARM on this platform:

This function is implemented using nanosleep(2) by pausing for seconds seconds or until a signal occurs. Consequently, in this implementation, sleeping has no effect on the state of process timers, and there is no special handling for SIGALRM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm @arnaud-lb. This is what the man-page says.

@Herz3h
Copy link

Herz3h commented Apr 26, 2024

Did this patch work for you @windaishi ?

Still facing the issue with this patch, althrough error is a bit different:

Fatal error: Maximum execution time of 30+2 seconds exceeded (terminated) in Unknown on line 0

Usually it gives the file path and line but not with this patch for some reason.

@arnaud-lb
Copy link
Member

@Herz3h this specific error message occurs when the script takes too long to shutdown after a timeout. Do you confirm the message is printed too early? Also, did you apply the two changes in this PR?

@windaishi
Copy link
Contributor Author

@Herz3h yes it did.

@windaishi windaishi changed the title Use ITIMER_REAL for timeout handling on Apple Silicon system Use ITIMER_REAL for timeout handling on Apple Silicon systems May 17, 2024
@iluuu1994 iluuu1994 self-requested a review as a code owner May 25, 2024 21:58
@arnaud-lb arnaud-lb closed this in 272da51 May 28, 2024
@arnaud-lb
Copy link
Member

Thank you @windaishi !

@gainlinejono
Copy link

Hi,

Has this been merged in with 8.3? I'm still experiencing this issue with 8.3 but not with 8.2.

Thanks

Jonathan

@jdecool
Copy link

jdecool commented Jun 26, 2024

According to Github, it's available in 8.3.9RC1 and 8.2.21RC1

CleanShot 2024-06-26 at 17 06 34@2x

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

Successfully merging this pull request may close these issues.

10 participants