question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mediator breaks out of the logical CallContext

See original GitHub issue

I’m having trouble with my mediator pipeline. I’m using the IRequestPostProcessor to implement both some workflow behavior and generic logging tasks.

Some of my mediator handlers are requesting the current user from HttpContext.Current.User, and for the most part, this works just fine. But lately we have experienced that the http context is not available.

I’m not 100% sure about this, but I think it’s a question of setting continueOnCapturedContext to false when calling next() in the RequestPostProcessorBehavior-implementation. At least, replacing the implementation with my own implementation that does not include the .ConfigureAwait(false) seems to solve the problem.

Is this a known problem? Is there a known solution?

(We’re still on MediatR 3.01)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:39 (39 by maintainers)

github_iconTop GitHub Comments

2reactions
danielmarbachcommented, May 24, 2018

@jbogard yes. Since MediateR is a general purpose in-process messaging library I’d say ConfigureAwait(false) could be argued as a good default value. Especially considering that MediatR encourages you to have SRP handlers that can return responses and those responses can then be assigned to something like the ViewModel or the UI. With that design you should never need to access something that is context-aware inside a handler, thus ConfigureAwait(false) actually enforces that design decision.

1reaction
seesharpercommented, May 25, 2018

As long as we are in the world of System.Web, there is no guarantee that this will work anyway.

Stay away from ConfigureAwait(false) and you should be good.

By staying away I mean code that accesses the ambient context (eg HttpContent.Current )should not be asynchronously executed using ConfigureAwait(false)

.Net Framework 4.7.1 introduces the concept of Execution steps that seems to address this issue although I have never tested this myself. https://blogs.msdn.microsoft.com/dotnet/2017/09/13/net-framework-4-7-1-asp-net-and-configuration-features/

Read more comments on GitHub >

github_iconTop Results From Across the Web

CallContext Class (System.Runtime.Remoting.Messaging)
CallContext is a specialized collection object similar to a Thread Local Storage for method calls and provides data slots that are unique to...
Read more >
StrangeIoC - The Big, Strange How-To
The Mediator (which is allowed to inject the context dispatcher) abstracts the bit of View that is concerned with communicating with the rest...
Read more >
[PATCH v5 00/10] TEE mediator (and OP-TEE) support in ...
Then generic vSMC handler will call selected mediator when it intercept SMC/HVC that belongs to TEE OS or TEE application. Signed-off-by: Volodymyr Babchuk ......
Read more >
Addressing the Challenges of Aggregational and Temporal ...
The mediator will intercept the query, compare the contexts involved, introduce appropriate component conversions, and generate a mediated query that reconciles ...
Read more >
Android Interface Definition Language (AIDL)
The Android Interface Definition Language (AIDL) is similar to other IDLs: it lets you define the programming interface that both the client and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found