8000 Improve error messages for failed connections by clue · Pull Request #270 · reactphp/socket · GitHub
[go: up one dir, main page]

Skip to content
8000

Improve error messages for failed connections #270

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

Merged
merged 6 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Lo 8000 ading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Avoid garbage memory references on PHP < 7.4
  • Loading branch information
clue committed Sep 3, 2021
commit 115097f9ce959852f8e1556fd055136aaa74b5cc
20 changes: 20 additions & 0 deletions src/DnsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ function ($resolve, $reject) use (&$promise, &$resolved, $uri, $connector, $host
$e->getCode(),
$e
);

// 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);
}

throw $e;
Expand Down
20 changes: 20 additions & 0 deletions src/SecureConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ public function connect($uri)
$e->getCode(),
$e
);

// 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);
}

throw $e;
Expand Down
0