Li-GL opened a new pull request, #4327:
URL: https://github.com/apache/streampark/pull/4327
<!--
Thank you for contributing to StreamPark! Please make sure that your code
changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
## Contribution Checklist
- If this is your first time, please read our contributor guidelines:
[Submit Code](https://streampark.apache.org/community/submit_guide/submit_code).
- Make sure that the pull request corresponds to a [GITHUB
issue](https://github.com/apache/streampark/issues).
- Name the pull request in the form "[Feature] Title of the pull request",
where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Fill out the template below to describe the changes contributed by the
pull request. That will give reviewers the context they need to do the review.
- If the PR is unfinished, add `[WIP]` in your PR title, e.g.,
`[WIP][Feature] Title of the pull request`.
-->
## What changes were proposed in this pull request
<!--(For example: This pull request proposed to add checkstyle plugin).-->
## Brief change log
新创建一个streampark服务并启动后,添加一个新任务并启动,会一直starting,持续4分钟,原因是doWatch()方法线程A与appFuture异步执行线程B发生死锁,线程A持有当前对象实例(this)的锁,线程B中有两个lazy
val懒加载需要等这个锁,导致死锁。
```
死锁时间线:
1. Thread-A: 获取锁 (this.synchronized)
2. Thread-A: 创建Future并提交到线程池
3. Thread-B: 从线程池取出任务开始执行
Thread-B: 尝试执行 updateState(...)
Thread-B: 如果需要锁,会阻塞等待(因为Thread-A持有锁)
4. Thread-A: 调用 Await.ready() 等待Future完成
5. Thread-A: 一直等待Thread-B完成
6. Thread-B: 一直等待Thread-A释放锁
→ 死锁!
```
After creating a new StreamPark service and starting it, when adding and
launching a new task, it remains in the "starting" state continuously for 4
minutes. The reason is that a deadlock occurs between thread A of the
`doWatch()` method and thread B executing `appFuture` asynchronously. Thread A
holds the lock of the current object instance (`this`), while thread B contains
two `lazy val` lazy-loaded variables that need to wait for this same lock,
resulting in a deadlock.
```
Timeline of the Deadlock:
1. Thread-A: Acquires the lock (this.synchronized)
2. Thread-A: Creates Futures and submits them to the thread pool
3. Thread-B: Takes a task from the thread pool and starts execution
Thread-B: Attempts to execute updateState(...)
Thread-B: If it needs the lock, it blocks waiting (because Thread-A
holds the lock)
4. Thread-A: Calls Await.ready() to wait for Future completion
5. Thread-A: Keeps waiting for Thread-B to complete
6. Thread-B: Keeps waiting for Thread-A to release the lock
→ Deadlock occurs!
```
<!--*(for example:)*
- *Add maven-checkstyle-plugin to root pom.xml*
-->
## Verifying this change
<!--*(Please pick either of the following options)*-->
This change is a trivial rework / code cleanup without any test coverage.
*(or)*
This change is already covered by existing tests, such as *(please describe
tests)*.
*(or)*
This change added tests and can be verified as follows:
<!--*(example:)*
- *Added integration tests for end-to-end.*
- *Added *Test to verify the change.*
- *Manually verified the change by testing locally.* -->
## Does this pull request potentially affect one of the following parts
- Dependencies (does it add or upgrade a dependency): (yes / no)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]