uioprty opened a new issue, #17464:
URL: https://github.com/apache/dolphinscheduler/issues/17464

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar issues.
   
   
   ### What happened
   
   When a worker receives an SQL task for the first time, it loads the driver 
class. If there are many tasks of multiple datasource types concurrently for 
the first time, a deadlock may occur, causing the thread to hang.
   
   see: 
https://medium.com/@priyaaggarwal24/avoiding-deadlock-when-using-multiple-jdbc-drivers-in-an-application-ce0b9464ecdf
   
   ### What you expected to happen
   
   Workers run normally.
   
   ### How to reproduce
   
   A number of SQL task instances from different data source types were already 
queued up and awaiting execution before the Worker started.
   
   Here is a demo.
   
   ```
   public class DeadLockTest {
   
       public static void main(String[] args) throws InterruptedException {
           ExecutorService es = Executors.newFixedThreadPool(2);
           es.execute(() -> {
               try {
                   Class.forName("com.mysql.cj.jdbc.Driver");
               } catch (ClassNotFoundException e) {
                   throw new RuntimeException(e);
               }
           });
   
           es.execute(() -> {
               try {
                   Class.forName("com.clickhouse.jdbc.ClickHouseDriver");
               } catch (ClassNotFoundException e) {
                   throw new RuntimeException(e);
               }
           });
   
           es.shutdown();
           while (!es.isTerminated()) {
               Thread.sleep(500);
               System.out.println("waiting");
           }
           System.out.println("end");
   
       }
   }
   ```
   
   openjdk version: 1.8.0_412
   
   jstack result:
   
   <img width="1132" height="610" alt="Image" 
src="https://github.com/user-attachments/assets/fc860bd2-5bf0-4721-b196-e8febd146025";
 />
   
   ### Anything else
   
   suggestion: remove Class.forName while getting connection.
   
   ### Version
   
   3.2.x
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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]

Reply via email to