Hello there
I'm trying to get results from views REST display.
Problem
I'v got 3 views (at least same problem with only 2 views), it's seems the results of the first views results is duplicate in all other results ....
How to reproduce
Create 2 views with rest display. It's views from a search API index but I think this change nothing.
here the blueprint I used
[
{
"requestId":"req-1",
"action":"view",
"uri":"/search/card-push-cold",
"headers": {
"Accept": "application/json"
}
},
{
"requestId":"req-2",
"action":"view",
"uri":"/search/card-content",
"headers": {
"Accept": "application/json"
}
}
]Response body of req5 contains the response of req1,req2,req3,req4
| Comment | File | Size | Author |
|---|---|---|---|
| #58 | subrequests-3049395-change-request-type.patch | 605 bytes | p.kasianov |
| #45 | 3049395-page-cache.png | 88.33 KB | phenaproxima |
| #26 | image.png | 129.74 KB | e0ipso |
| #9 | change_request_type-63049395-09.patch | 615 bytes | kensae |
| #6 | 3049395-06.patch | 551 bytes | voleger |
Issue fork subrequests-3049395
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
musa.thomasOk my bad it seem it's something wrong with my authication provider patch
https://www.drupal.org/project/subrequests/issues/3049343
Comment #3
musa.thomasAfter investigation it seem not providing from my patch, but of the other authiticate methode.
If I remove the patch and use only basic auth I get the same results.
It's seems this only work with cookie authentification method
Comment #4
volegerfaced the same issue, the first request populate own response to the following request responses in the queue. I'm looking to the cause of the problem
Comment #5
volegerPlease follow #3050383: PageCache cannot handle multiple main requests
This patch helps me receive the correct response.
I suggest to set a status for that issue Closed(works as designed) as this looks like a Drupal core issue.
Comment #6
volegerTrying to fix this issue on the module level. Looks like `\Drupal::service('page_cache_kill_switch')->trigger();` is a great solution for this issue. I put this call after generating the response of the request list item. And this fix works for my case. I had used the `simple_oauth` module for authorization and made calls to the JSON:API and the REST api resource endpoints without duplicating responses now.
So I don't need the patch from #5 #3050383: PageCache cannot handle multiple main requests anymore as that patch has an influence on the caching of all requests to the project.
Comment #7
hari604 commentedHi voleger,
Thank you for sharing your patch.
But it doesn't seem to work for me, whereas https://www.drupal.org/project/drupal/issues/3050383 works, with it's effect on caching as you have mentioned.
Could you please share any insight on this?
I am using Drupal 8.7.3.
Thank you.
Comment #8
voleger#6 patch tries to handle the cache invalidation. Instead of breaking the caching mechanism in page_cache module using the patch from #3050383: PageCache cannot handle multiple main requests issue, the #6 patch trigger events subscribers which should (as I understand) invalidate caches generated during processed request in the queue.
Current dIfferences between solutions:
- #3050383: PageCache cannot handle multiple main requests patch breaks caching of any kind of requests (API calls or just Drupal frontend requests);
- #6 patch breaks caching only for requests that processed by the module (request to the
subrequests.front-controllerroute)Both of the patches require some attention to improvement in cache handling.
Comment #9
kensae commentedI've change the request type in the processBatchSequence function of the SubrequestsManager class from MASTER_REQUEST to SUB_REQUEST and this solves the issue for me. I don't know if changing the type has other consequences.
Comment #10
andsigno82 commentedHad the same issue, #3 gave me a shot to investigate further, since i don't use cookie nor basic auth but oauth with Bearer.
Confirmed as #3 reported, this is due to authentication method used in first request.
You MUST pass Authorization header string (which comprises your method, of course).
In my case, request(s) worked with Bearer token in EACH AND EVERY request and subrequest (co-dependent) made.
I left MASTER_REQUEST in line 72 of
src/SubrequestsManager.php. no further patching required.Comment #11
e0ipsoThanks for the investigation @andsigno82! Hopefully others can post weather or not the problem is solved for them.
Comment #12
andsigno82 commentedI must correct my first statement as reported in #10
The Bearer is mandatory to be included ONLY IN THE FIRST request (master). subsequent sub-requests WHICH DEPENDS FROM MASTER REQUEST, "grabs" the token from the master.
in case you have parallel requests which NOT DEPENDS from master, actually creating another master, Auth Header must be RE-INCLUDED
Comment #13
decipheredIt appears that this issue occurs even when authorization isn't required, e.g., public endpoints.
While the patch from #9 "works", in my case it drastically increases the query time.
Currently investigating solutions and alternative workarounds.
Comment #14
luksakThe patch solves the issue for me.
I can confirm the performance decrease described in #13. In my case it is quite drastic. @Deciphered have you made progress on this?
Comment #15
decipheredSorry Lukas, but I opted instead to no longer use this module and handle the multiple requests via the frontend.
Comment #16
james marks commentedI can confirm that passing the Authorization header string with each request and subrequest resolves this problem (for me, at least).
Comment #17
chalk commentedSeems #9 solved the issue for me. Will do more testing later, but at first look it works.
Comment #18
andre.bonon#9 solved the issue for me too.
here is the blueprint used:
Comment #19
maggie_s commentedThis also happens in version 3 of Drupal 9.
the change to make it work was in src/SubrequestsManager.php
->handle($request, HttpKernelInterface::MASTER_REQUEST);
to
->handle($request, HttpKernelInterface::SUB_REQUEST);
Comment #21
volegerAdded required changes to the Unit test
Comment #22
paulmckibbenConfirming #9 fixes the issue for me in Drupal core 8.9.14
Comment #23
volegerMR is the same as #9 but with test coverage changes and it is mergeable
Comment #24
j.b commentedI was having the same problem.
Same results on different action view requests.
#9 works.
Drupal version 9.2.0
Can we have this merged on the latest version of the module please ?
Comment #25
j.b commentedAfter further testing, i still get the problem...
Response body of req5 contains the response of req1,req2,req3 and req4.
Comment #26
e0ipsoAs you can see in the screenshot and in the comments above merging this would have a drastic consequence. I think others have mentioned that this can be solved otherwise:
Maybe there could be some dedicated code that forwards headers from the request to all subrequests in the blueprint?
Comment #27
KevinVanRansbeeck commentedThe patch gives the right results, but it seems to break tests/caching?
Is there a way to achieve the same result with requests that do NOT use authentication as @Deciphered also encountered?
Comment #28
Syntapse commentedWill this work in apline linux?
im getting errors trying to apply the patch with composer.
Comment #29
phenaproximaCore has an example of this; its exception handler creates a subrequest to the appropriate exception page (403 or 404), and forwards everything along. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21EventSubs....
Comment #30
phenaproximaOne question, probably for @e0ipso to answer, is why Subrequests specifically treats the subrequests as master requests. By all rights, as far as I can tell, the subrequests should be explicitly marked as subrequests.
Was that only done in order to make Page Cache work for subrequests?
Comment #31
lauriii#30: Based on #26, that seems to have been the reason. It says explicitly that merging this would have a drastic consequence, with a screenshot referring to Page Cache.
Comment #33
phenaproximaI've added a functional test in a new merge request, and it reproduces the bug as described. As long as page caching is guaranteed to engage, this will occur.
I also added this new test to the existing merge request, so we will be able to see clearly that whatever fix we ultimately land on, really fixes it.
Comment #34
phenaproximaThe original merge request is pretty out of date, and I guess that approach will not be taken anyway since as @e0ipso points out, it will have an outsized effect.
At least now we have some solid test coverage on which to build a fix ;)
Comment #36
phenaproximaAfter consulting with @effulgentsia, I think a viable approach for now is to store the cache ID on the request itself, rather than have the PageCache middleware statically cache it. That's what my newest merge request implements, and the new test passes with that, so I'm going to mark this as needing review.
Meanwhile, I think we should also implement a similar fix in core -- PageCache should store the cache ID with the request, if it hasn't already.
Comment #37
phenaproximaComment #38
e0ipsoI left a nitpick and a question there. Great job! It is always so awesome to get a patch and some additional test coverage!!!
Comment #39
phenaproximaComment #40
e0ipso@phenaproxima I cannot spot why we have a test failure. Did you mention it works in your local?
Comment #41
phenaproximaYeah, passes for me. I'm using a 9.5.x checkout of core and PHP 8.1.
Comment #42
e0ipsoAlright, re-testing with those parameters to see if that is the cause.
Comment #43
e0ipsoWell, look at that. Not only it did not fix the failing test, but now we have 3 failures.
Comment #44
phenaproximaYeah, this is a thing that I think was deprecated in PHPUnit 8. We should probably just open another issue to use the replacement assertions (assertIsInt(), assertIsFloat(), etc.)
Comment #45
phenaproximaI know why this is failing: Drupal CI runs all of its tests against a Drupal installation in a subdirectory, precisely to catch these kinds of bugs. My localhost doesn't install Drupal in a subdirectory.
With some Docker trickery, I managed to reproduce it. Here, once the bug occurred, were the entries in the page cache database table:
Notice those first two entries: they aren't prefixed with the
web/directory, which is where Drupal was legitimately installed. That's no good. Subrequests didn't prefix the subdirectory, thereby resulting in the cache miss.So I guess we'll have to fix both bugs here. Assigning to myself to wrangle this one.
Comment #47
rajeshreeputraUpdated change request type patch as per new release.
Comment #48
rajeshreeputrachange_request_type-63049395-09.patch patch was failing, hence created new subrequests-3049395-change-request-type-47.patch patch, but not required as both seems identical hence removing.
Comment #49
dan_metille commentedI've upgraded to Drupal 10 and use the
Merge request !9patch, but I'm then getting the following error:And I'm really getting lost into this thread. What is the status of this issue and how to fix it?
Comment #50
e0ipsoThis issue is currently stalled.
Comment #51
mglamanPinged @phenaproxima, he's not working on this. I'm going to take some time to go through the issue and MRs/patches.
Comment #52
mglamanTests are passing, now. However I think the approach is wrong. We should be using SplObjectStorage to store cache IDs per-request object instead of the current approach. See \Drupal\Core\Path\CurrentPathStack for an example.
Comment #53
mglamanOkay, the tests are fixed. I also updated the implementation to be something to be more resilient than relying on manipulating the request object.
Comment #54
e0ipsoThis looks wonderful!
Thanks for the work, and the patience everyone!!
Comment #56
e0ipsoComment #58
p.kasianov commentedUp!
Updated patch from #47 for new release 3.0.12
Comment #59
kevinquillen commentedThis issue is marked fixed, is the patch in 58 still needed?
Comment #60
mglamanThis bug is fixed. The patch changes the type of request sent, which looks like a different issue.