diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index 903f5cd2a1f5..9bc3fa73ed6f 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -307,31 +307,37 @@ public int deleteAllSubWorkProcessByParentId(int processInstanceId){ */ public void removeTaskLogFile(Integer processInstanceId){ - LogClientService logClient = new LogClientService(); + LogClientService logClient = null; - List taskInstanceList = findValidTaskListByProcessId(processInstanceId); + try { + logClient = new LogClientService(); + List taskInstanceList = findValidTaskListByProcessId(processInstanceId); - if (CollectionUtils.isEmpty(taskInstanceList)){ - return; - } - - for (TaskInstance taskInstance : taskInstanceList){ - String taskLogPath = taskInstance.getLogPath(); - if (StringUtils.isEmpty(taskInstance.getHost())){ - continue; - } - int port = Constants.RPC_PORT; - String ip = ""; - try { - ip = Host.of(taskInstance.getHost()).getIp(); - }catch (Exception e){ - // compatible old version - ip = taskInstance.getHost(); + if (CollectionUtils.isEmpty(taskInstanceList)) { + return; } + for (TaskInstance taskInstance : taskInstanceList) { + String taskLogPath = taskInstance.getLogPath(); + if (StringUtils.isEmpty(taskInstance.getHost())) { + continue; + } + int port = Constants.RPC_PORT; + String ip = ""; + try { + ip = Host.of(taskInstance.getHost()).getIp(); + } catch (Exception e) { + // compatible old version + ip = taskInstance.getHost(); + } - // remove task log from loggerserver - logClient.removeTaskLog(ip,port,taskLogPath); + // remove task log from loggerserver + logClient.removeTaskLog(ip, port, taskLogPath); + } + }finally { + if (logClient != null) { + logClient.close(); + } } }