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

高并发下异常问题 #131

Closed
yinhz opened this issue Nov 15, 2019 · 16 comments
Closed

高并发下异常问题 #131

yinhz opened this issue Nov 15, 2019 · 16 comments

Comments

@yinhz
Copy link

yinhz commented Nov 15, 2019

您好,我们遇到以下情况,还请您帮忙看下。
我已经将FreeSql代码加到自己的解决方案中。
以下单元测试方法,在并发量低的时候,不会抛出以下异常。
但是并发量较高的时候,会出现以下异常,并且主程序无法捕获。
看了下是在 析构函数中,有 trans.RollBak(),这时候 trans 是 Null,虽然前面有判断trans是否为null,就导致了异常的出现。
由于无法捕获,会导致程序崩溃。。

1
2
3

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

第二张图,堆栈信息,显示的是
image

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

把相同的测试代码,换成 sqlserver 或 mysql 试试,看看是不是驱动层报的

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

这个析构函数,我用 try 包装一下吧

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

看测试代码 uow 用 using 了,会自动调用 Dispose 方法

为什么析构函数执行的时候, tran != null 条件还成立呢?

@yinhz
Copy link
Author

yinhz commented Nov 15, 2019

嗯,我们调试的时候也觉得很奇怪。
首先我们没有在程序中使用异步,都是同步的程序。
而且只有当sql执行效率较低(我故意去掉了数据库的索引),并发较高的时候才会出现。

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

我提交下代码,方便配合引用代码测试下吗

@yinhz
Copy link
Author

yinhz commented Nov 15, 2019

额,您的代码我在本地有修改过。
1个是签名,二个是UOW不为Null的时候,即使只查询,也会开启事务。

我会把最新的UOW的代码覆盖到我本地这里,做下测试。

@yinhz
Copy link
Author

yinhz commented Nov 15, 2019

是只修改了 UnitOfWork 这个类的代码吗

2881099 pushed a commit that referenced this issue Nov 15, 2019
@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

if (_isdisposed) return;
_isdisposed = true;

我把这些代码,全改成了
if (Interlocked.Increment(ref _disposeCounter) != 1) return;

@yinhz
Copy link
Author

yinhz commented Nov 15, 2019

1

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

所以,这个 oracle 那个驱动内部报的 null 错误。

第二张图,堆栈信息,显示的是
image

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

把完整的堆栈信息发一下,StackTrace

@yinhz
Copy link
Author

yinhz commented Nov 15, 2019

1

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

你的代码行,和我这边怎么不一样

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

兄弟把搜索 ctrl + f, ~ 把项目内所有析构方法去掉试下

@2881099
Copy link
Collaborator

2881099 commented Nov 15, 2019

新代码,您试下。。DbContext 类的析构可能是有这个问题。。

2881099 pushed a commit that referenced this issue Nov 15, 2019
@2881099 2881099 closed this as completed May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants