Forward Warning:
I'm fully aware that the use of .Result in the context shown below is flat-out wrong and should be avoided at all costs. I know what the correct approach is ("async/await all the way") and this is what I'm using.
The nature of this question has more to do with the infrastructure of db-drivers: Oracle vs Ms-Sql-Server. It's an academic question for the most part.
System.Web.MVC.dll: ver. 5.2.3.0 (MVC5)
EntityFramework.dll: ver. 6.1.3
EntityFramework.SqlServer.dll: ver. 6.1.3
Oracle.ManagedDataAccess: ver. 4.121.2.0 (oracle driver ver 12.2.0.1.0)
Oracle.ManagedDataAccess.EntityFramework: ver. 6.121.2.0 (oracle driver ver 12.2.0.1.0)
Consider the following repository and its invocation within an ASP.NET MVC controller:
public class MyRepository {
[...]
public async Task<SomeEntity> GetFirstFooAsync() => await new SomeEFContext().FooTable.FirstOrDefaultAsync();
}
public class SomeController : Controller {
public ActionResult SomeAction() {
var result = new MyRepository.GetFirstFooAsync().Result; //<-- intentionally crappy approach
[...]
}
}
The above piece of code doesn't deadlock when the underlying db is Oracle. But this exact same piece of code causes a deadlock when targeting MS-Sql-Server via the associated driver provided by MS for EF.
The deadlock is the expected behaviour for such crappy code and thus Ms-Sql-Server-Drivers are in the Green and the Managed-Oracle-Db-Drivers are in the "Weird" (because they don't cause a deadlock).
- Why the oracle-driver doesn't cause a deadlock? Does it use
.ConfigureAwait(false)
internally or some other tweak? - If the oracle driver indeed uses a tweak should I be concerned that it might have undesirable side-effects even when programming the invocation appropriately - aka, like so:
public class SomeController : Controller {
public async Task<ActionResult> SomeAction() {
var result = await new MyRepository.GetFirstFooAsync();
[...]
}
}
If we write code properly using "async/await all the way" then everything works both in oracle and ms-sql-server as intended in our dev-machines and in our QA.
However I want to verify that there isn't something amiss with the implementation of the oracle drivers which can cause problems even when a proper approach is being used. If nothing else, I'm curious as to what is it that oracle drivers are doing differently than the Ms-Sql-Server-drivers and can side-step the deadlock in the first (read: intentionally crappy) implementation.