Problem/Motivation

When a priority is added to tags named 'http_client_middleware', the priority is ignored. HTTP client middlewares should use standard service_id_collector so priorities work out of the box.

Steps to reproduce

Create two HTTP middlewares, define them like so:

  test.http_middleware1:
    class: Drupal\test\HttpMiddleware1
    tags:
      - { name: http_client_middleware, priority: -100 }

  test.http_middleware2:
    class: Drupal\test\HttpMiddleware2
    tags:
      - { name: http_client_middleware, priority: 100 }

You'll see the first middleware is executed first, since it's defined first. Instead the second middleware should be executed first since priorities work in highest->lowest order.

Proposed resolution

Deprecate \Drupal\Core\DependencyInjection\Compiler\GuzzleMiddlewarePass and replace with service_id_collector.

Release notes snippet

GuzzleMiddlewarePass has been removed in favor of the generic TaggedHandlersPass, code interacting with GuzzleMiddlewarePass should use TaggedHandlersPass instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dpi created an issue. See original summary.

dpi’s picture

I'm at a loss for how to test this in a Kernel test, so posting the fix as I have it.

dpi’s picture

Issue summary: View changes
longwave’s picture

Status: Active » Needs review

Nice find!

Pretty sure compiler passes are considered internal anyway, we can hopefully just remove the class and the reference to it in CoreServiceProvider.

Not sure we need a test either, as TaggedHandlersPassTest covers this case and we're just using it as intended here rather than a custom pass that does something similar but not as well.

As a followup it looks like ContextProvidersPass could have the same treatment, it is very similar.

longwave’s picture

Status: Needs review » Needs work
Issue tags: -GuzzleHttp

Remembered this following discussion of Guzzle middleware in another issue.

I think we can remove the GuzzleMiddlewarePass entirely, there is no need to keep it around.

dhirendra.mishra’s picture

Status: Needs work » Needs review
FileSize
2.5 KB

I have remove GuzzleMiddlewarePass occurance..Please review it if it hepls.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, this looks correct to me, and I don't see the value in adding an explicit test although core committers might decide otherwise.

larowlan’s picture

I've pinged other committers about the BC implications (if any) here

larowlan’s picture

Issue tags: +Needs change record

Discussed the BC implications with catch who felt that these would be similar to Param converters

Can we get a change notice for the removal of the class?

Thanks

We'll update the BC policy to explicitly list compiler passes when this goes in

longwave’s picture

larowlan’s picture

Issue summary: View changes
Issue tags: +9.3.0 release notes

Saving issue credits for longwave for writing the change record 💾

Updated the BC policy

Added a release notes snippet.

Verified there's no contrib usage of this

  • larowlan committed 02e787a on 9.3.x
    Issue #3215397 by dpi, dhirendra.mishra, longwave: Service tag priority...
larowlan’s picture

Committed 02e787a and pushed to 9.3.x. Thanks!

Published the change record

larowlan’s picture

Category: Task » Bug report
Issue tags: +Bug Smash Initiative

I feel this is a bug, if priorities are ignored.

As a followup it looks like ContextProvidersPass could have the same treatment, it is very similar.

We could do this, however its less important there because by nature of how they work, contexts don't typical interact with each other and hence priority isn't important.

By their very nature, middlewares are expected to be reliably ordered, so that's why I've reclassified it as a bug.

dpi’s picture

Thanks @larowlan, thanks @longwave for the CR

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.