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

PHP Warning: Expected array for frame X #103

Closed
bileslav opened this issue Feb 6, 2022 · 5 comments · Fixed by #104
Closed

PHP Warning: Expected array for frame X #103

bileslav opened this issue Feb 6, 2022 · 5 comments · Fixed by #104
Assignees
Labels
Milestone

Comments

@bileslav
Copy link

bileslav commented Feb 6, 2022

Hello,

It seems that some exceptions cannot be correctly converted to a string.

This is what sometime appears in my log (notice the empty stack traces):

[Sun, 06 Feb 2022 17:26:14 +0300] .ERROR: RuntimeException: Connection to 1.2.3.4:5678?hostname=qwerty.net timed out after 10 seconds (ETIMEDOUT) in /path-to-app/vendor/react/socket/src/TimeoutConnector.php:42
Stack trace:
#0 /path-to-app/vendor/react/promise/src/RejectedPromise.php(28): React\Socket\TimeoutConnector::React\Socket\{closure}()
#1 /path-to-app/vendor/react/promise/src/Promise.php(134): React\Promise\RejectedPromise->then()
#2 /path-to-app/vendor/react/promise/src/Promise.php(168): React\Promise\Promise::React\Promise\{closure}()
#3 /path-to-app/vendor/react/promise/src/Promise.php(148): React\Promise\Promise->settle()
#4 /path-to-app/vendor/react/promise/src/Promise.php(237): React\Promise\Promise->reject()
#5 /path-to-app/vendor/react/promise-timer/src/functions.php(183): React\Promise\Promise::React\Promise\{closure}()
#6 /path-to-app/vendor/react/event-loop/src/ExtUvLoop.php(120): React\Promise\Timer\{closure}()
#7 [internal function]: React\EventLoop\ExtUvLoop->React\EventLoop\{closure}()
#8 /path-to-app/vendor/react/event-loop/src/ExtUvLoop.php(232): uv_run()
#9 /path-to-app/vendor/react/event-loop/src/Loop.php(211): React\EventLoop\ExtUvLoop->run()
#10 /path-to-app/src/Main.php(22): React\EventLoop\Loop::run()
#11 /path-to-app/app(7): Main->__construct()
#12 {main}

Next RuntimeException: Connection to tcp://qwerty.net:443 failed because connection to proxy failed (ECONNREFUSED) in /path-to-app/vendor/clue/socks-react/src/Client.php:189
Stack trace:
#0 {main}

Next RuntimeException: Connection to tls://qwerty.net:443 failed because connection to proxy failed (ECONNREFUSED) in /path-to-app/vendor/react/socket/src/SecureConnector.php:75
Stack trace:
#0 {main}

And at the same time, in the PHP log:

[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 0 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 1 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 2 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 3 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 4 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 5 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 6 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 7 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 8 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 9 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 10 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 11 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 12 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 13 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 14 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 15 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 16 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 17 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 18 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 19 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 20 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 21 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 22 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 23 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 0 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 1 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 2 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 3 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 4 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 5 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 6 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 7 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 8 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 9 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 10 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 11 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 12 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 13 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 14 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 15 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
[06-Feb-2022 17:26:14 Europe/Moscow] PHP Warning:  Expected array for frame 16 in /path-to-app/vendor/monolog/monolog/src/Monolog/Logger.php on line 565
@SimonFrings
Copy link
Contributor

@bileslaw thanks for bringing this up. 👍

I'm having a hard time to reproduce this behavior, is there a script on your side that I can test this with?
I'm also not entirely sure but it seems like this is coming from the Monolog project and not from reactphp-socks.

What are your thoughts on this?

@bileslav
Copy link
Author

bileslav commented Feb 7, 2022

Hi @SimonFrings 👋

I've just been able to find the minimal working example and the causing code.
The problem seems to come from the use of references in foreach:

try {
	(function (): never {
		throw new Exception();
	})();
} catch (Exception $e) {
	/**
	 * The following code is taken from:
	 * /clue/socks-react/src/Client.php
	 * /react/socket/src/SecureConnector.php
	 * (maybe it's repeated elsewhere)
	 */

	// avoid garbage references by replacing all closures in call stack.
	// what a lovely piece of code!
	$r = new \ReflectionProperty('Exception', 'trace');
	$r->setAccessible(true);
	$trace = $r->getValue($e);
	// Exception trace arguments are not available on some PHP 7.4 installs
	// @codeCoverageIgnoreStart
	foreach ($trace as &$one) {
		if (isset($one['args'])) {
			foreach ($one['args'] as &$arg) {
				if ($arg instanceof \Closure) {
					$arg = 'Object(' . \get_class($arg) . ')';
				}
			}
		}
	}
	// @codeCoverageIgnoreEnd
	$r->setValue($e, $trace);

	echo "{$e}\n"; // empty trace and the warning
}

@clue clue added the bug label Feb 8, 2022
@clue clue added this to the v1.4.0 milestone Feb 8, 2022
@clue
Copy link
Owner

clue commented Feb 8, 2022

@bileslaw Thank you for reporting, I can indeed reproduce the problem you're seeing with the gist you've provided!

This is indeed a nasty bug that has been introduced a while ago with #82. This only happens on PHP 7+ when printing the exception trace ($exception->getTraceAsString()) which makes it kind of hard to test and is also why this hasn't caught our attention earlier.

I've started looking into this and will file a PR as soon as time allows 👍

@bileslav
Copy link
Author

bileslav commented Feb 8, 2022

@clue Thank you for the prompt action!

Just in case, I note again: the same bug is also located in react/socket at least.

@clue
Copy link
Owner

clue commented Feb 10, 2022

@bileslaw Don't worry, on it already! See upstream PRs reactphp/socket#284 ad reactphp/dns#191.

I hope this helps! 👍 If so, consider supporting this project, for example by becoming a sponsor ❤️

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

Successfully merging a pull request may close this issue.

3 participants