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

一个单机串行的脚本任务同时发起多次执行,小概率出现其中一个任务被终止的情况 #3557

Open
lancepan opened this issue Oct 18, 2024 · 0 comments

Comments

@lancepan
Copy link

lancepan commented Oct 18, 2024

Please answer some questions before submitting your issue. Thanks!

Which version of XXL-JOB do you using?

2.3.1

Expected behavior

只有一台执行机的情况下,对一个单机串行的脚本任务同时发起多次执行,期望结果是发起的执行排队等待,并全部执行完

Actual behavior

会偶发性的出现一个任务失败的情况,失败日志都是
image

Steps to reproduce the behavior

简单创建一个powershell任务,脚本代码为:
image
通过多线程,接口调用该任务发起多次执行,我个人测试用机器在60次时较为容易复现该上述出错情形

Other information

个人推测是对任务线程缓存ConcurrentMap<Integer, JobThread>的复合操作导致的,推测如下
1.对同一任务发起多次执行时,由于任务线程缓存里还没有任务的线程
image
这段代码获取的jobThread和jobHandler都为null,则最后都会走到这一段代码,即调用registJobThread方法
image
此时若有多个请求任务的线程同时调用这段代码
image
即同时创建了多个任务线程,然后在调用jobThreadRepository.put(jobId, newJobThread)的时候,因为单个put本身是同步的,
导致先put进的任务线程会被后put的任务线程覆盖,并且被调用oldJobThread.interrupt()标志线程状态中断
image

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

1 participant