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

Different errors while tyring to drupal drush #862

Closed
sepal opened this issue Aug 6, 2019 · 4 comments · Fixed by #864
Closed

Different errors while tyring to drupal drush #862

sepal opened this issue Aug 6, 2019 · 4 comments · Fixed by #864
Milestone

Comments

@sepal
Copy link

sepal commented Aug 6, 2019

Hi,

I'm trying to debug some issues with drupals cache layer using sentry, but encountered some problems. I'm using v2 of the library without the raven module.

I want to basically send a custom event if a certain cache id is set, so that I can debug what causes the faulty cache entry. My code basically looks likes this:

function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) {
 if ($cid == 'some cache id') {
    $dsn = variable_get('recruiter_sentry_dsn');
    Sentry\init(['dsn' => $dsn]);

    Sentry\configureScope(function (Sentry\State\Scope $scope) use ($cid, $data, $bin) {
      $scope->setTag('cid', $cid);
      $scope->setExtra('data', $data);
      $scope->setExtra('bin', $bin);
    });

    Sentry\captureMessage("cache_set");
  }
    
  return _cache_get_object($bin)->set($cid, $data, $expire);
}

This works for web requests, but when I run drush, which works over the CLI, for example for cron requests or refreshing the cache periodically, I get some error messages.

The first issue is that sentry expects $_SERVER['HTTP_USER_AGENT'] to be a string or a numeric value. Since drupal is called from the CLI there is no user agent and I get the following error:

<h1>Additional uncaught exception thrown while handling exception.</h1><h2>Original</h2><p>Zend\Diactoros\Exception\InvalidArgumentException: Invalid header value type; must be a string or numeric; received NULL in Zend\Diactoros\HeaderSecurity::assertValid() (line 139 of /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/HeaderSecurity.php).</p><h2>Additional</h2><p>Zend\Diactoros\Exception\InvalidArgumentException: Invalid header value type; must be a string or numeric; received NULL in Zend\Diactoros\HeaderSecurity::assertValid() (line 139 of /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/HeaderSecurity.php).</p><hr />
Fatal error: Uncaught Zend\Diactoros\Exception\InvalidArgumentException: Invalid header value type; must be a string or numeric; received NULL in /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/HeaderSecurity.php:139
Stack trace:
#0 /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/MessageTrait.php(398): Zend\Diactoros\HeaderSecurity::assertValid(NULL)
#1 [internal function]: Zend\Diactoros\ServerRequest->Zend\Diactoros\{closure}(NULL)
#2 /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/MessageTrait.php(401): array_map(Object(Closure), Array)
#3 /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/MessageTrait.php(338): Zend\Diactoros\ServerRequest->filterHeaderValue(Array)
#4 /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/RequestTrait.php(80): Zend\Diactoros\ServerRequest->setHeaders(Array)
#5 /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/ServerRequest.php(99): Zend\Diactoros\Se in /var/www/html/profiles/recruiter/vendor/zendframework/zend-diactoros/src/HeaderSecurity.php on line 139

I can get passed that by setting the user agent to an empty string manually. If I do that, the second issue arrises. I get a lot of this warnings and my drush process hangs:

curl_multi_info_read(): supplied resource is not a valid cURL Multi  [warning]
Handle resource MultiRunner.php:88

Is there something I have to set if I want to use sentry with php script called via bash, i.e. not a web request?

@ste93cry
Copy link
Collaborator

ste93cry commented Aug 7, 2019

The issue may lie around this line:

$request = isset($_SERVER['REQUEST_METHOD']) && \PHP_SAPI !== 'cli' ? ServerRequestFactory::fromGlobals() : null;

Can you try to disable the RequestIntegration integration and see if it works?

@Jean85
Copy link
Collaborator

Jean85 commented Aug 7, 2019

You should check for the value of $_SERVER['REQUEST_METHOD']; maybe it's set but it's null?

@sepal
Copy link
Author

sepal commented Aug 8, 2019

You should check for the value of $_SERVER['REQUEST_METHOD']; maybe it's set but it's null?

yes, $_SERVER['REQUEST_METHOD'] is set to null, but \PHP_SAPI returns 'cli' so $request is still set to null and ServerRequestFactory::fromGlobals() is not run. I can see that the assertion fails before the code in RequestIntegration is run, so disabling RequestIntegration will not help I guess.

You can find the backtrace here:
https://gist.github.com/sepal/6a501b1884265b78269a07f0eebba686

@Jean85
Copy link
Collaborator

Jean85 commented Aug 8, 2019

Thanks! So this is the culprit:

$request = ServerRequestFactory::fromGlobals();

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

Successfully merging a pull request may close this issue.

3 participants