Azure / elastic-db-tools

Elastic database tools client library allows ADO.NET developers to create applications that implement and use the pattern known as database sharding in Azure SQL Database.
MIT License
145 stars 102 forks source link

ShardMapManager TryGetListShardMap throws System.ExecutionEngineException with too many inits #153

Open brainded opened 7 years ago

brainded commented 7 years ago

I recently experienced a issue with the ShardMapManager that may or may not be related to how I used it. I built a Interface to allow me to resolve my EF Context and inside the context I init a ShardMapManager to find the shard it is to use. This was working fine up until my Multitenant Application reached ~160 databases. When I hit that point, my Webjob responsible for doing scheduled tasks against each shard was unexpectedly failing. To troubleshoot the issue I needed to remote debug into my Webjob. All I got was the following: Exception of type 'System.ExecutionEngineException' was thrown.

After reading up on this exception, it seems to be related to some unmanaged code messing up the state of the application. On a hunch I pulled out the ShardMapManager and only init once and give a reference of it to my context. This resolved my issue but I wanted to put it on your radar if anyone else is experiencing this issue.

jaredmoo commented 7 years ago

Wow, ExecutionEngineException? How bizarre. Thanks for the heads up.

Yes it's best to only create one instance of ShardMapManager since it contains a cache, and it's better to have only one instance of the cache used throughout your application. :)

brainded commented 7 years ago

I may have jumped the gun... moving the ShardMapManager out helped alleviate but not resolve the problem. I will continue working on trying to find the root cause.