Skip to content

[Fix-18201][TaskPlugin] Fix RemoteShell task NullPointerException and…#18210

Merged
SbloodyS merged 2 commits into
apache:devfrom
leocook:fix-18201-remoteshell-npe
May 4, 2026
Merged

[Fix-18201][TaskPlugin] Fix RemoteShell task NullPointerException and…#18210
SbloodyS merged 2 commits into
apache:devfrom
leocook:fix-18201-remoteshell-npe

Conversation

@leocook
Copy link
Copy Markdown
Contributor

@leocook leocook commented May 1, 2026

Was this PR generated or assisted by AI?

YES, assisted by Claude Sonnet 4.6 for root cause analysis and code fix.

Purpose of the pull request

close #18201

Brief change log

PR #17800 changed runRemoteAndProcessLines() to use channel.getInvertedOut() instead of channel.setOut(ByteArrayOutputStream), which introduced two regression bugs:

  1. NPE: getInvertedOut() is called before channel.open() completes, returns null
  2. Pipe closed after 0 cycles: MINA SSHD's ChannelPipedInputStream throws IOException when command produces no output

This PR reverts to the setOut(ByteArrayOutputStream) approach while keeping the line-by-line processing improvement from #17800.

Verify this pull request

This pull request is already covered by existing tests, such as RemoteExecutorTest (12 tests, all passed).

Manually verified the change by testing RemoteShell task against a remote SSH server on local standalone deployment.

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

Verify this pull request

This pull request is already covered by existing tests, such as RemoteExecutorTest (12 tests, all passed).
Manually verified on local standalone deployment with RemoteShell task against a remote SSH server:

Before fix:
image

111

After fix:
222

@ruanwenjun ruanwenjun force-pushed the fix-18201-remoteshell-npe branch from 2d7cbf9 to b314cde Compare May 2, 2026 12:26
@ruanwenjun ruanwenjun added this to the 3.4.2 milestone May 2, 2026
@SbloodyS SbloodyS added the bug Something isn't working label May 2, 2026
@SbloodyS SbloodyS requested a review from Copilot May 3, 2026 02:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes regressions introduced in #17800 for the RemoteShell task by avoiding ChannelExec.getInvertedOut() (which can be null before channel open completes) and by preventing MINA SSHD pipe errors when commands produce no output.

Changes:

  • Rework RemoteExecutor.runRemoteAndProcessLines() to use channel.setOut(ByteArrayOutputStream) instead of getInvertedOut().
  • Update RemoteExecutorTest mocks to simulate setOut(OutputStream) behavior and cover empty-output/non-zero-exit scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteExecutor.java Switches RemoteShell output capture away from getInvertedOut() to avoid NPE/pipe issues; preserves line-based parsing.
dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/test/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteExecutorTest.java Adjusts unit tests to mock setOut() output delivery and updates coverage for empty output / exit status behavior.
Comments suppressed due to low confidence (1)

dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/test/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteExecutorTest.java:269

  • testTrackWithEmptyLogOutput will spend significant time sleeping because RemoteExecutor.track() calls Thread.sleep(TRACK_INTERVAL) when no lines are read. With getTaskPid() mocked to return a non-empty pid and then an empty pid, this test will hit the sleep path multiple times (making the unit test suite slow/flaky). Consider stubbing Thread.sleep (e.g., via Mockito static mocking) or adjusting the test setup so the loop exits without waiting.
    void testTrackWithEmptyLogOutput() throws Exception {
        RemoteExecutor remoteExecutor = spy(new RemoteExecutor(sshConnectionParam));
        String taskId = "1234";
        ChannelExec channel = Mockito.mock(ChannelExec.class, RETURNS_DEEP_STUBS);

        doReturn("9527").doReturn("").when(remoteExecutor).getTaskPid(taskId);
        when(clientSession.auth().verify().isSuccess()).thenReturn(true);
        when(clientSession.createExecChannel(anyString())).thenReturn(channel);
        // no output → readLines=0 → sleep once, then getTaskPid returns "" → exit
        when(channel.getExitStatus()).thenReturn(0);
        when(channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0))
                .thenReturn(EnumSet.of(ClientChannelEvent.CLOSED));

        Assertions.assertDoesNotThrow(() -> remoteExecutor.track(taskId));

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

leocook added 2 commits May 3, 2026 22:42
… Pipe closed error

Revert the channel output reading approach introduced in apache#17800 from
getInvertedOut() back to setOut(ByteArrayOutputStream), which fixes two
regression bugs:
1. NPE: getInvertedOut() returns null before channel.open() completes
2. Pipe closed after 0 cycles: ChannelPipedInputStream throws IOException
   when command produces no output
…n failure

- Fix err.toString() using platform default charset, now uses UTF-8 explicitly
- Reorder logic to consume stdout before checking exitStatus, so lineConsumer
  receives output even when command exits non-zero (improves diagnostics in UI)
@leocook leocook force-pushed the fix-18201-remoteshell-npe branch from 28a7e1a to 63de8a1 Compare May 3, 2026 15:02
@SbloodyS SbloodyS requested a review from Copilot May 4, 2026 08:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 60%)

See analysis details on SonarQube Cloud

@SbloodyS SbloodyS merged commit 756f2f2 into apache:dev May 4, 2026
125 of 127 checks passed
@leocook leocook deleted the fix-18201-remoteshell-npe branch May 4, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [REMOTESHELL] remote shell task error in v3.4.1

4 participants