Problem/Motivation
Trying to set this up for Anon users to start with. We have a Kubernetes pod configured with Nginx and a Varnish VCL that works for anonymous users without this module enabled. I assume this module provides access to some of this configuration through the UI (as well as providing use with authenticated users - our real goal here).
We have swapped out our entire working vcl with the default one and made the couple IP changes required (but used host names instead of IP). When caching is enabled for anon the site works fine for admin (since this isnt doing anything for auth users). But as soon as i go to a page as anon i get this error:
Error: Call to a member function getRequestUri() on null in Drupal\adv_varnish\CacheManager->cachingEnabled() (line 467 of modules/contrib/adv_varnish/src/CacheManager.php).
Checking that code (which i should have done earlier.. ughh) and i see this:
// Check if we can be on disabled domain.
$excluded_urls = explode(PHP_EOL, $this->config->get('available.excluded_urls'));
$request_uri = $this->request->getRequestUri();
It looks like if no exclude domain added to config this will crash. I tested by simply adding goggle.ca to the list and now it works.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3264583-Request-object-is-empty.patch | 2.55 KB | shumer |
| #14 | enabled.txt | 30.23 KB | liquidcms |
| #12 | composer.txt | 14.91 KB | liquidcms |
| #5 | varnish_2.png | 95.94 KB | shumer |
| #5 | varnish_1.png | 120.78 KB | shumer |
Comments
Comment #2
liquidcms commentedComment #3
shumer commentedComment #4
liquidcms commentedthis time it didnt seem to fix it.. not sure why not.. but tomorrow i'll do a patch to just bypass
Comment #5
shumer commentedHello @liquidcms
Error: Call to a member function getRequestUri()The getRequestUri performed on request object and returns the requested URI (path and query string).
This has no deal with Excluded domain option which can be empty.
Here is an example with the default VCL povided by module:
As you can see it works as expected. In your case it looks like your request object was empty.... which is weird.
Are your sure that there were no any additional steps done?
Have you tried to clear caches after module was installed/configured?
BR, Alex
Comment #6
shumer commentedIf you're going to make a patch. Can you add a debug to see the state of request?
Maybe this will help us to understand the problem and fix it properly.
Comment #7
maltaib1 commented@shumer, I have followed the instruction and deployed a copy of the default.vcl file with the required modifications.
It does not appear that the issue we are observing is linked to the varnish vcl config. If I leave our previously used varnish vcl in place and enable adv_varnish + configure + drush cr the same error is present... I even remove varnish altogether and got the same error showing up... so, I suspect it is something specific to our site/environment that might be causing this...
We deploy our site on a kubernetes cluster using the drupalwxt helm chart: https://github.com/drupalwxt/helm-drupal
We leverage a varnish pod, nginx pod, redis pods, php fpm pod and a mysql pod.
This won't help you figure out why, but I figured it might be worth noting.
Comment #8
liquidcms commentedDebugging locally (varnish not installed, no vcl, etc) and i see $this->request (CacheManager.php is always null). Is it possible this is not the correct way to inject this service for D9?
Comment #9
shumer commentedTo get the request we're using '@request_stack' service which is recommended way to get the request object.
In case of D9 specfic - my screenshots was done on the 9.3.5 Core.
Interesting moment that this is a Symfony component, I don't think that you overrride it somehow... unless you have somewhere calls to `pop` method from there.
Are you able to check the Symfony\Component\HttpFoundation\RequestStack
we're interested in value of:
you can debug `push` and `pop` methods to see how the Drupal handle the request lifecycle.
Also can you share the local setup with me? I can try to reproduce the issue to help you with the fix.
Comment #10
liquidcms commentedNot sure what local setup would be that you are referring to - i don't even have varnish installed for debugging this.
We have decided to not use this module at this time so not sure how much more time i can spend debugging this (sorry to just post and run) - but will try to debug inside the Symphony class directly to see what is going on (later this afternoon).
I have no custom code which is overriding this or popping anything from the stack. Could be in some contrib module i guess.
Comment #11
shumer commentedthat's can be our issue. Can you share the list of enabled contrib modules? Composer file maybe?
I'll try to reproduce that and maybe you'll be able to use the module :)
Comment #12
liquidcms commentedComposer.json is attached; note that it calls another module called wxt. This has its own large composer.json which pulls in a bunch more contrib modules (and Drupal core).
Comment #13
shumer commentedThat's fine.
One last thing can you also share
drush pml --status=enabledso I won't have to enable ALL of them
Comment #14
liquidcms commentedComment #15
shumer commentedThx for the list, I'll try to deploy the project at my local tomorrow,
Comment #16
shumer commentedQuestion.. the page where you see that error. is it build with the page manager?
Comment #17
shumer commented@liquidcms, can you try to replace:
with
if it works we can prepare proper patch and make a new release.
Comment #18
arnaud-brugnon commentedHi,
Just kick out stupid purge modules from my project and i got a brand new issue.
Wonderfull
I am so glad that someone got the same error before me.
Btw, the fix purposed in #17 only solve an error to bring another one.
Error: Call to a member function getHost() on null in Drupal\adv_varnish\CacheManager->cachingEnabled()
Like request object is empty, it s logical that every call's to it fail :(
Comment #19
arnaud-brugnon commentedAdding those line at the beginning of the method seems to solve every issue
Comment #20
arnaud-brugnon commentedHere 's my full patch btw
diff --git a/src/CacheManager.php b/src/CacheManager.php
--- a/src/CacheManager.php (date 1645106840879)
+++ b/src/CacheManager.php (date 1645106840879)
@@ -450,6 +450,9 @@
*/
public function cachingEnabled() {
+ if (empty($this->request)) {
+ $this->request = \Drupal::request();
+ }
// Check if user has permission to bypass varnish.
if ($this->account->hasPermission('bypass advanced varnish cache')) {
$this->log(RfcLogLevel::DEBUG, 'Cache disabled by Bypass Varnish permission.');
Comment #21
liquidcms commented@shumer, yes, replacing that line fixes my error and the error is then on the following line as mentioned by arnaud-brugnon.
also, this happens on every page. we don't use page manager.
Comment #22
liquidcms commentedComment #23
shumer commentedThanks for helping with this issue guys,
@amaud-brugnon - that was a great idea, actually I was done some research for this issue, looks like we have the same situation with the Forms in Drupal Core...
Anyway, I did a patch that work in Drupal Core way. IF someone of you can test it would be awesome.
In case of success I'll do a new release.
P.S. it works fine at my local setup.
Comment #24
shumer commentedComment #25
shumer commentedSorry wrong file was attached.
The proper one here:
Comment #26
shumer commentedComment #27
arnaud-brugnon commentedWell, it don't see why this may not work.
I will test it tomorow in the morning and i will let you know.
Btw, good work with your module, i love it (i waste so much time to this stupid purges modules)
Comment #28
arnaud-brugnon commentedIt works for me.
Perfect, thanks
Comment #32
shumer commentedNice to hear :)
Thanks guys for your help on this issue. New release with the fix was published.
Comment #33
liquidcms commentedHaven't tested much else; but this fix does fix the issue reported here. Thanks for the quick update.