ruanwenjun opened a new issue #5427: URL: https://github.com/apache/dolphinscheduler/issues/5427
**Describe the bug** When I execute a `sql` task and set to sent an email, the task will fail. But the email is sent successfully. **To Reproduce** Steps to reproduce the behavior, for example: 1. Create a `sql` task and set send email.  2. execute 3. See error in work log ```java [INFO] 2021-05-07 23:05:11.932 org.apache.dolphinscheduler.service.alert.AlertClientService:[100] - sync alert send, host : localhost, port : 50052, groupId : 2, title : Ds test [ERROR] 2021-05-07 23:05:21.944 org.apache.dolphinscheduler.service.alert.AlertClientService:[110] - sync alert send error org.apache.dolphinscheduler.remote.exceptions.RemotingTimeoutException: wait response on the channel Host{address='localhost:50052', ip='localhost', port=50052} timeout 10000 at org.apache.dolphinscheduler.remote.NettyRemotingClient.sendSync(NettyRemotingClient.java:278) at org.apache.dolphinscheduler.service.alert.AlertClientService.sendAlert(AlertClientService.java:105) at org.apache.dolphinscheduler.service.alert.AlertClientService.sendAlert(AlertClientService.java:87) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.sendAttachment(SqlTask.java:458) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.resultProcess(SqlTask.java:332) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.executeFuncAndSql(SqlTask.java:264) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.handle(SqlTask.java:153) at org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread.run(TaskExecuteThread.java:169) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) [ERROR] 2021-05-07 23:05:21.945 - [taskAppId=TASK-8-211-220]:[276] - execute sql error: null [ERROR] 2021-05-07 23:05:21.945 - [taskAppId=TASK-8-211-220]:[159] - sql task error: java.lang.NullPointerException [ERROR] 2021-05-07 23:05:21.945 org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread:[182] - task scheduler failure java.lang.NullPointerException: null at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.sendAttachment(SqlTask.java:459) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.resultProcess(SqlTask.java:332) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.executeFuncAndSql(SqlTask.java:264) at org.apache.dolphinscheduler.server.worker.task.sql.SqlTask.handle(SqlTask.java:153) at org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread.run(TaskExecuteThread.java:169) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) [WARN] 2021-05-07 23:05:21.949 org.apache.dolphinscheduler.remote.NettyRemotingClient:[366] - connect to Host{address='192.168.1.3:49735', ip='192.168.1.3', port=49735} error io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /192.168.1.3:49735 Caused by: java.net.ConnectException: Connection refused at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716) at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:702) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at java.lang.Thread.run(Thread.java:748) ``` **Which version of Dolphin Scheduler:** -[dev] **Additional context** This is mainly caused by the following code, you can find in `NettyRemotingClient`. When we send an attachment, `AlertClientService` will use `NettyRemotingClient` to call `AlertServer`. The `responseFuture.waitResponse()` will always be null, and this method will throw exception. ```java final ResponseFuture responseFuture = new ResponseFuture(opaque, timeoutMillis, null, null); channel.writeAndFlush(command).addListener(future -> { if (future.isSuccess()) { responseFuture.setSendOk(true); return; } else { responseFuture.setSendOk(false); } responseFuture.setCause(future.cause()); responseFuture.putResponse(null); logger.error("send command {} to host {} failed", command, host); }); /* * sync wait for result */ Command result = responseFuture.waitResponse(); if (result == null) { if (responseFuture.isSendOK()) { throw new RemotingTimeoutException(host.toString(), timeoutMillis, responseFuture.getCause()); } else { throw new RemotingException(host.toString(), responseFuture.getCause()); } } ``` BYW, there seems to be no difference between `send` and `sendSync` in `NettyRemotingClient` **Requirement or improvement** Use a handler to decode the result of `channel.writeAndFlush(command)` or discard the result. -- 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. For queries about this service, please contact Infrastructure at: [email protected]
