Skip to content
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

LinqToDB.Reflection.TypeAccessor1[[System.__Canon, mscorlib]]..cctor() wait long System.Linq.Expressions.Expression1[[System.__Canon, mscorlib]].Compile() #3650

Open
weipingpingping opened this issue Jul 7, 2022 · 13 comments · May be fixed by #3653

Comments

@weipingpingping
Copy link

Describe your issue.

If you have a question, first try to check our documentation, especially FAQ and search in issues and discussions - maybe your question already answered there.

If you still have questions or want to start general discussion, please create new topic in discussions.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:
1)
Stack trace:
OS Thread Id: 0x1ce48 (70)
        Child SP               IP Call Site
00000205d9c06328 00007ff652b82650 [InlinedCallFrame: 00000205d9c06328] System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(System.IRuntimeMethodInfo)
00000205d9c06328 00007ff86e5ac48b [InlinedCallFrame: 00000205d9c06328] System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(System.IRuntimeMethodInfo)
00000205d9c06300 00007ff86e5ac48b DomainNeutralILStubClass.IL_STUB_PInvoke(System.IRuntimeMethodInfo)
00000205d9c063b0 00007ff86e7fd6e9 System.Reflection.Emit.DynamicMethod.CreateDelegate(System.Type, System.Object)
00000205d9c06400 00007ff86c4ffed2 System.Linq.Expressions.Compiler.LambdaCompiler.Compile(System.Linq.Expressions.LambdaExpression, System.Runtime.CompilerServices.DebugInfoGenerator)
00000205d9c06440 00007ff86c508ac8 System.Linq.Expressions.Expression`1[[System.__Canon, mscorlib]].Compile()
00000205d9c06480 00007ff813b2647e LinqToDB.Reflection.TypeAccessor`1[[System.__Canon, mscorlib]]..cctor()
00000205d9c06bb0 00007ff86ee96ba3 [GCFrame: 00000205d9c06bb0] 
00000205d9c07568 00007ff86ee96ba3 [HelperMethodFrame: 00000205d9c07568] 
00000205d9c07670 00007ff813b1f470 LinqToDB.Reflection.TypeAccessor`1[[System.__Canon, mscorlib]]..ctor()
00000205d9c079f0 00007ff86ee96ba3 [DebuggerU2MCatchHandlerFrame: 00000205d9c079f0] 
00000205d9c079a8 00007ff86ee96ba3 [GCFrame: 00000205d9c079a8] 
00000205d9c07ac0 00007ff86ee96ba3 [GCFrame: 00000205d9c07ac0] 
00000205d9c07b78 00007ff86ee96ba3 [HelperMethodFrame_2OBJ: 00000205d9c07b78] System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
00000205d9c07d70 00007ff86dea8c7e System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
00000205d9c07df0 00007ff86dea8a1b System.Activator.CreateInstance(System.Type, Boolean)
00000205d9c07e40 00007ff813b1d6c2 LinqToDB.Reflection.TypeAccessor.GetAccessor(System.Type)
00000205d9c07ee0 00007ff8152c1a9e LinqToDB.Linq.Builder.ExpressionBuilder+c__DisplayClass178_0.g__CollectParameters|0(System.Type, System.Reflection.MethodBase, System.Collections.ObjectModel.ReadOnlyCollection`1)
00000205d9c08020 00007ff8152b2526 LinqToDB.Linq.Builder.ExpressionBuilder.ProcessProjection(System.Collections.Generic.Dictionary`2, System.Linq.Expressions.Expression)
00000205d9c08350 00007ff8152ac47e LinqToDB.Linq.Builder.SelectContext..ctor(LinqToDB.Linq.Builder.IBuildContext, System.Linq.Expressions.LambdaExpression, LinqToDB.Linq.Builder.IBuildContext[])
00000205d9c08440 00007ff8151a1841 LinqToDB.Linq.Builder.SelectBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c085b0 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08620 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08770 00007ff816e8448b LinqToDB.Linq.Builder.OrderByBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08930 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c089a0 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08af0 00007ff8151a33cb LinqToDB.Linq.Builder.FirstSingleBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08c40 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08cb0 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08e00 00007ff815183f4d LinqToDB.Linq.Builder.ExpressionBuilder.Build[[System.__Canon, mscorlib]]()
00000205d9c08f60 00007ff814b27ccc LinqToDB.Linq.Query`1[[System.__Canon, mscorlib]].CreateQuery(LinqToDB.IDataContext, System.Linq.Expressions.Expression)
00000205d9c09080 00007ff8146d78d5 LinqToDB.Linq.Query`1[[System.__Canon, mscorlib]].GetQuery(LinqToDB.IDataContext, System.Linq.Expressions.Expression ByRef)
00000205d9c09170 00007ff8146bff4f LinqToDB.Linq.ExpressionQuery`1[[System.__Canon, mscorlib]].GetQuery(System.Linq.Expressions.Expression ByRef, Boolean)
00000205d9c09200 00007ff8146bac3e LinqToDB.Linq.ExpressionQuery`1[[System.__Canon, mscorlib]].System.Linq.IQueryProvider.Execute[[System.__Canon, mscorlib]](System.Linq.Expressions.Expression)
2)  308 threads   locked by  0x1ce48 (70)  long time

### Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

```c#
<code with error and mapping classes>

Environment details

linq2db version: 2.9.6
Database Server: mysql
Database Provider: MySql.Data.dll
Operating system: windows server 2016
.NET Framework: 4.8.1

@sdanyliv
Copy link
Member

sdanyliv commented Jul 7, 2022

I think just call stack is not enough. Show Model classes and LINQ query. Also remove from issue not relevant issues template text.

Also 2.9.x version is no longer supported. Check on the latest linq2db version.

@weipingpingping
Copy link
Author

I Checked on the latest linq2db version , the code of LinqToDB.Reflection.TypeAccessor was not changed.

@sdanyliv
Copy link
Member

sdanyliv commented Jul 7, 2022

I do not ask to check TypeAccessor code, check that your issue still exists in latest linq2db release.

@weipingpingping
Copy link
Author

I mean, the static constructor of LinqToDB.Reflection.TypeAccessor first compiles the lamda for a long time。later ,this LambdaCompiler of the same lamda will be locked .this issue still exists

@sdanyliv
Copy link
Member

sdanyliv commented Jul 7, 2022

Show your LINQ query and model.

@weipingpingping
Copy link
Author

weipingpingping commented Jul 7, 2022

  1. LINQ query and model
var currentOffOn = (from p in db.TMS_USER_ONOFF
			where p.ENTERPRISE_ID == enterpriseId && p.PARK_ID == parkAndPerson.park.ID && p.STATUS == "ON" && p.PERSON_CODE == parkAndPerson.person.PERSON_CODE
			select p into a
			select new { a.DATETIME_CREATED, a.PERSON_STATUS, a.JOB_TYPE, a.TASK_WAREHOUSE } into p
			orderby p.DATETIME_CREATED descending
			select p).FirstOrDefault();
  1. dbspy decompile
parameterExpression = Expression.Parameter(typeof(TMS_USER_ONOFF), "a");
    var source2 = source.Select(Expression.Lambda(Expression.New(methodof(<>f__AnonymousType202<DateTime?, string, string, string>..ctor(<DATETIME_CREATED>j__TPar, <PERSON_STATUS>j__TPar, <JOB_TYPE>j__TPar, <TASK_WAREHOUSE>j__TPar)), new Expression[]
    {
        Expression.Property(parameterExpression, methodof(ModelBase.get_DATETIME_CREATED())),
        Expression.Property(parameterExpression, methodof(TMS_USER_ONOFF.get_PERSON_STATUS())),
        Expression.Property(parameterExpression, methodof(TMS_USER_ONOFF.get_JOB_TYPE())),
        Expression.Property(parameterExpression, methodof(TMS_USER_ONOFF.get_TASK_WAREHOUSE()))
    }, new MemberInfo[]
    {
        methodof(<>f__AnonymousType202<DateTime?, string, string, string>.get_DATETIME_CREATED()),
        methodof(<>f__AnonymousType202<DateTime?, string, string, string>.get_PERSON_STATUS()),
        methodof(<>f__AnonymousType202<DateTime?, string, string, string>.get_JOB_TYPE()),
        methodof(<>f__AnonymousType202<DateTime?, string, string, string>.get_TASK_WAREHOUSE())
    }), new ParameterExpression[]
    {
        parameterExpression
    }));
    parameterExpression = Expression.Parameter(typeof(<>f__AnonymousType202<DateTime?, string, string, string>), "p");
    CS$<>8__locals4.currentOffOn = source2.OrderByDescending(Expression.Lambda(Expression.Property(parameterExpression, methodof(<>f__AnonymousType202<DateTime?, string, string, string>.get_DATETIME_CREATED())), new ParameterExpression[]
    {
        parameterExpression
    })).FirstOrDefault();

3) windbg

 LinqToDB.Reflection.TypeAccessor.GetAccessor(System.Type)
    PARAMETERS:
        type (0x00000205d9c07ee0) = 0x00000206ac6c76b8

0:070> !DumpObj /d 00000206ac6c76b8
Name:        System.RuntimeType
MethodTable: 00007ff86d937738
EEClass:     00007ff86d896a88
Size:        56(0x38) bytes
Type Name:   <>f__AnonymousType202`4[[System.Nullable`1[[System.DateTime, mscorlib]], mscorlib],[System.String, mscorlib],[System.String, mscorlib],[System.String, mscorlib]]
Type MT:     00007ff8b3b4af00

0:070> !DumpMT /d 00007ff8b3b4af00
EEClass:         00007ff8b3dc26a0
Module:          00007ff8b29216a8
Name:            f__AnonymousType202`4[[System.Nullable`1[[System.DateTime, mscorlib]], mscorlib],[System.String, mscorlib],[System.String, mscorlib],[System.String, mscorlib]]
mdToken:         00000000020000cc

3)linqtodb code

public class TypeAccessor<T> : TypeAccessor
{
    static TypeAccessor()
    {
        // Create Instance.
        //
        var type = typeof(T);

        if (type.IsValueTypeEx())
        {
            _createInstance = () => default;
        }
        else
        {
            var ctor = type.IsAbstractEx() ? null : type.GetDefaultConstructorEx();

            if (ctor == null)
            {
                Expression<Func<T>> mi;

                if (type.IsAbstractEx()) mi = () => ThrowAbstractException();
                else                     mi = () => ThrowException();

                var body = Expression.Call(null, ((MethodCallExpression)mi.Body).Method);

                _createInstance = Expression.Lambda<Func<T>>(body).Compile();
            }
            else
            {
                _createInstance = Expression.Lambda<Func<T>>(Expression.New(ctor)).Compile();
            }
        }

@sdanyliv
Copy link
Member

sdanyliv commented Jul 7, 2022

Add TMS_USER_ONOFF class - it is Model.

@weipingpingping
Copy link
Author

weipingpingping commented Jul 7, 2022

internal class TMS_USER_ONOFF
{
	public string PARK_ID { get; set; }
	public string TASK_WAREHOUSE { get; set; }
	public string PERSON_CODE { get; set; }
	public string JOB_TYPE { get; set; }
	public string STATUS { get; set; }
	public string PERSON_STATUS { get; set; }
	public DateTime DATETIME_ON { get; set; }
	public DateTime? DATETIME_OFF { get; set; }
	public decimal? HOUR_ON { get; set; }

	public TMS_USER_ONOFF()
	{
		base.STATE = "A";
	}
}

@weipingpingping
Copy link
Author

weipingpingping commented Jul 7, 2022

image
this png is the 0x1ce48 (70) thread .Hold the lock will have 23 hours.308 threads locked by 0x1ce48 (70) long time. the 14 thread is the one of
the 308 threads.

0:070> !clrstack

OS Thread Id: 0x1ce48 (70)
        Child SP               IP Call Site
00000205d9c06328 00007ff652b82650 [InlinedCallFrame: 00000205d9c06328] System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(System.IRuntimeMethodInfo)
00000205d9c06328 00007ff86e5ac48b [InlinedCallFrame: 00000205d9c06328] System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(System.IRuntimeMethodInfo)
00000205d9c06300 00007ff86e5ac48b DomainNeutralILStubClass.IL_STUB_PInvoke(System.IRuntimeMethodInfo)
00000205d9c063b0 00007ff86e7fd6e9 System.Reflection.Emit.DynamicMethod.CreateDelegate(System.Type, System.Object)
00000205d9c06400 00007ff86c4ffed2 System.Linq.Expressions.Compiler.LambdaCompiler.Compile(System.Linq.Expressions.LambdaExpression, System.Runtime.CompilerServices.DebugInfoGenerator)
00000205d9c06440 00007ff86c508ac8 System.Linq.Expressions.Expression`1[[System.__Canon, mscorlib]].Compile()
00000205d9c06480 00007ff813b2647e LinqToDB.Reflection.TypeAccessor`1[[System.__Canon, mscorlib]]..cctor()
00000205d9c06bb0 00007ff86ee96ba3 [GCFrame: 00000205d9c06bb0] 
00000205d9c07568 00007ff86ee96ba3 [HelperMethodFrame: 00000205d9c07568] 
00000205d9c07670 00007ff813b1f470 LinqToDB.Reflection.TypeAccessor`1[[System.__Canon, mscorlib]]..ctor()
00000205d9c079f0 00007ff86ee96ba3 [DebuggerU2MCatchHandlerFrame: 00000205d9c079f0] 
00000205d9c079a8 00007ff86ee96ba3 [GCFrame: 00000205d9c079a8] 
00000205d9c07ac0 00007ff86ee96ba3 [GCFrame: 00000205d9c07ac0] 
00000205d9c07b78 00007ff86ee96ba3 [HelperMethodFrame_2OBJ: 00000205d9c07b78] System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
00000205d9c07d70 00007ff86dea8c7e System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
00000205d9c07df0 00007ff86dea8a1b System.Activator.CreateInstance(System.Type, Boolean)
00000205d9c07e40 00007ff813b1d6c2 LinqToDB.Reflection.TypeAccessor.GetAccessor(System.Type)
00000205d9c07ee0 00007ff8152c1a9e LinqToDB.Linq.Builder.ExpressionBuilder+c__DisplayClass178_0.g__CollectParameters|0(System.Type, System.Reflection.MethodBase, System.Collections.ObjectModel.ReadOnlyCollection`1)
00000205d9c08020 00007ff8152b2526 LinqToDB.Linq.Builder.ExpressionBuilder.ProcessProjection(System.Collections.Generic.Dictionary`2, System.Linq.Expressions.Expression)
00000205d9c08350 00007ff8152ac47e LinqToDB.Linq.Builder.SelectContext..ctor(LinqToDB.Linq.Builder.IBuildContext, System.Linq.Expressions.LambdaExpression, LinqToDB.Linq.Builder.IBuildContext[])
00000205d9c08440 00007ff8151a1841 LinqToDB.Linq.Builder.SelectBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c085b0 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08620 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08770 00007ff816e8448b LinqToDB.Linq.Builder.OrderByBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08930 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c089a0 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08af0 00007ff8151a33cb LinqToDB.Linq.Builder.FirstSingleBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08c40 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08cb0 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
00000205d9c08e00 00007ff815183f4d LinqToDB.Linq.Builder.ExpressionBuilder.Build[[System.__Canon, mscorlib]]()
00000205d9c08f60 00007ff814b27ccc LinqToDB.Linq.Query`1[[System.__Canon, mscorlib]].CreateQuery(LinqToDB.IDataContext, System.Linq.Expressions.Expression)
00000205d9c09080 00007ff8146d78d5 LinqToDB.Linq.Query`1[[System.__Canon, mscorlib]].GetQuery(LinqToDB.IDataContext, System.Linq.Expressions.Expression ByRef)
00000205d9c09170 00007ff8146bff4f LinqToDB.Linq.ExpressionQuery`1[[System.__Canon, mscorlib]].GetQuery(System.Linq.Expressions.Expression ByRef, Boolean)
00000205d9c09200 00007ff8146bac3e LinqToDB.Linq.ExpressionQuery`1[[System.__Canon, mscorlib]].System.Linq.IQueryProvider.Execute[[System.__Canon, mscorlib]](System.Linq.Expressions.Expression)

0:014> !clrstack

OS Thread Id: 0x16768 (14)
        Child SP               IP Call Site
000000c476df72a8 00007ff885ce9334 [HelperMethodFrame: 000000c476df72a8] 
000000c476df73b0 00007ff813b1f470 LinqToDB.Reflection.TypeAccessor`1[[System.__Canon, mscorlib]]..ctor()
000000c476df7730 00007ff86ee96ba3 [DebuggerU2MCatchHandlerFrame: 000000c476df7730] 
000000c476df76e8 00007ff86ee96ba3 [GCFrame: 000000c476df76e8] 
000000c476df7800 00007ff86ee96ba3 [GCFrame: 000000c476df7800] 
000000c476df78b8 00007ff86ee96ba3 [HelperMethodFrame_2OBJ: 000000c476df78b8] System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
000000c476df7ab0 00007ff86dea8c7e System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)
000000c476df7b30 00007ff86dea8a1b System.Activator.CreateInstance(System.Type, Boolean)
000000c476df7b80 00007ff813b1d6c2 LinqToDB.Reflection.TypeAccessor.GetAccessor(System.Type)
000000c476df7c20 00007ff8152c1a9e LinqToDB.Linq.Builder.ExpressionBuilder+c__DisplayClass178_0.g__CollectParameters|0(System.Type, System.Reflection.MethodBase, System.Collections.ObjectModel.ReadOnlyCollection`1)
000000c476df7d60 00007ff8152b2526 LinqToDB.Linq.Builder.ExpressionBuilder.ProcessProjection(System.Collections.Generic.Dictionary`2, System.Linq.Expressions.Expression)
000000c476df8090 00007ff8152ac47e LinqToDB.Linq.Builder.SelectContext..ctor(LinqToDB.Linq.Builder.IBuildContext, System.Linq.Expressions.LambdaExpression, LinqToDB.Linq.Builder.IBuildContext[])
000000c476df8180 00007ff8151a1841 LinqToDB.Linq.Builder.SelectBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
000000c476df82f0 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
000000c476df8360 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
000000c476df84b0 00007ff816e8448b LinqToDB.Linq.Builder.OrderByBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
000000c476df8670 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
000000c476df86e0 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
000000c476df8830 00007ff8151a33cb LinqToDB.Linq.Builder.FirstSingleBuilder.BuildMethodCall(LinqToDB.Linq.Builder.ExpressionBuilder, System.Linq.Expressions.MethodCallExpression, LinqToDB.Linq.Builder.BuildInfo)
000000c476df8980 00007ff8151a02ce LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(LinqToDB.Linq.Builder.ExpressionBuilder, LinqToDB.Linq.Builder.BuildInfo)
000000c476df89f0 00007ff8151864fc LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(LinqToDB.Linq.Builder.BuildInfo)
000000c476df8b40 00007ff815183f4d LinqToDB.Linq.Builder.ExpressionBuilder.Build[[System.__Canon, mscorlib]]()
000000c476df8ca0 00007ff814b27ccc LinqToDB.Linq.Query`1[[System.__Canon, mscorlib]].CreateQuery(LinqToDB.IDataContext, System.Linq.Expressions.Expression)
000000c476df8dc0 00007ff8146d78d5 LinqToDB.Linq.Query`1[[System.__Canon, mscorlib]].GetQuery(LinqToDB.IDataContext, System.Linq.Expressions.Expression ByRef)
000000c476df8eb0 00007ff8146bff4f LinqToDB.Linq.ExpressionQuery`1[[System.__Canon, mscorlib]].GetQuery(System.Linq.Expressions.Expression ByRef, Boolean)
000000c476df8f40 00007ff8146bac3e LinqToDB.Linq.ExpressionQuery`1[[System.__Canon, mscorlib]].System.Linq.IQueryProvider.Execute[[System.__Canon, mscorlib]](System.Linq.Expressions.Expression)

@weipingpingping
Copy link
Author

From the dump file, the 10 threads in the above figure are similar, all of which are different lamda expressions entering the static constructor, blocking different numbers of threads. Currently, there is a balance between reducing lamda compilation without blocking the running of the same lamda thread. In this case, the caller can decide what strategy to use. At present, my application is found because LinqToDB.Reflection.TypeAccessor blocks hundreds of threads, and at the same time, new 900 DbNorthwind (LinqToDB.Data.DataConnection) objects are created, resulting in the mysql database connection pool being allocated, causing the entire application to fail to work.

@sdanyliv
Copy link
Member

sdanyliv commented Jul 7, 2022

It is something weird, it should be handled by .NET Runtime correctly, but it's not. It would good to have some kind of small testing app which reproduces problem.
Anyway check #3653, I've tried to reduce Expression Compilation hits.

@weipingpingping
Copy link
Author

If can't reduce the blocking caused by lamda expression compilation, it is best to optimize it. Do not use LinqToDB.Data.DataConnection before compilation, because the number of connection objects in the data connection pool is limited. Because LinqToDB.Data.DataConnection is used up due to blocking caused by lamda expression compilation, the entire application hangs.

@weipingpingping
Copy link
Author

weipingpingping commented Jul 7, 2022

In my current situation, the maximum number of connections in the MySQL database connection pool is 100. At present, the 100 connection objects are blocked and used up.
image
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants