-
Notifications
You must be signed in to change notification settings - Fork 17
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
Register Middlewares as Transient to avoid clobber #958
Merged
gkinsman
merged 6 commits into
justeattakeaway:main
from
gkinsman:fix-middleware-lifetime
Nov 10, 2021
Merged
Register Middlewares as Transient to avoid clobber #958
gkinsman
merged 6 commits into
justeattakeaway:main
from
gkinsman:fix-middleware-lifetime
Nov 10, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…are pipeline gets its own instance. Without this, when multiple subscriptions are registered, middlewares clobber each other when built.
Codecov Report
@@ Coverage Diff @@
## main #958 +/- ##
==========================================
- Coverage 84.37% 84.27% -0.10%
==========================================
Files 131 131
Lines 3199 3206 +7
==========================================
+ Hits 2699 2702 +3
- Misses 500 504 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
src/JustSaying/Messaging/Middleware/Handle/HandlerMiddlewareBuilder.cs
Outdated
Show resolved
Hide resolved
tests/JustSaying.IntegrationTests/Fluent/Subscribing/WhenSubscribingToMultipleTopics.cs
Outdated
Show resolved
Hide resolved
- File scoped namespaces!
…gistered incorrectly
martincostello
approved these changes
Nov 10, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed this issue due to a failing test in JustSayingStack.
Most of our tests only establish a single subscription, which works fine. If there are multiple subscriptions however, then the second will resolve the same instance of
LoggingMiddleware
orSqsPostProcessorMiddleware
(the only middlewares that are resolved from DI). As those instances were already used to build the previous pipeline, they are already part of an existing pipeline, and therefore have_next
values that link them to the next step. When the second builder comes along and resolves the same middleware, it redirects the_next
to the second subscription. The end result is that the same handler is invoked for all subscriptions. Bad!This PR does the following to fix this:
_next
property has already been populated, which indicates that the middleware has been incorrectly registered and the single instance is already part of an existing pipeline. If there's only one subscription this won't throw, so it still works for apps that only have a single sub and single instance middlewares.