As @Elnur_Abdurrakhimov said we must cache the securityContext first and the call the getToken()->getUser()
when needed.
class RelationHelperExtension extends Twig_Extension
{
private $context;
public function __construct(SecurityContext $securityContext){
$this->context= $securityContext;
}
private function getUser(){
return $this->context->getToken()->getUser();
}