Skip to content

Commit

Permalink
Fix the bug that context will being overwritten when context copied (…
Browse files Browse the repository at this point in the history
…#488)

* Fix the bug that context will being overwritten when context copied

* Refactor CoroutineAspect to copy context keys from one coroutine to another

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed Dec 14, 2023
1 parent 33b3a12 commit 298aa46
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Aspect/CoroutineAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace FriendsOfHyperf\Telescope\Aspect;

use FriendsOfHyperf\Telescope\TelescopeContext;
use Hyperf\Context\Context;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Hyperf\Engine\Coroutine as Co;
Expand All @@ -36,7 +35,14 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$cid = Co::id();

$proceedingJoinPoint->arguments['keys']['callable'] = function () use ($callable, $cid, $keys) {
Context::copy($cid, $keys);
$from = Co::getContextFor($cid);
$current = Co::getContextFor();

foreach ($keys as $key) {
if (isset($from[$key])) {
$current[$key] = $from[$key];
}
}

$callable();
};
Expand Down

0 comments on commit 298aa46

Please sign in to comment.