int128 / int128/gradle-ssh-plugin

Stopping gradle task execution does not close the SSH connection

Open
#409 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Groovy
Stars
325
Forks
59
Avg merge
5h 29m
Merged PRs (30d)
6

Description

Environment info

null-null (groovy-ssh-2.11.2, jsch-0.2.5, groovy-3.0.17, java-17.0.4.1)
Gradle version: 8.4

Scenario:

  1. Run a gradle task that executes a program on remote server, recieves logs, and waits for program to stop executing.
  2. Killing the gradle task with CTRL+C, then confirming: Terminate batch job (Y/N)? with Y, the gradle task stops.

But the program executing on the remote server does not stop.
It does not matter if the gradle task is run from IntelliJ Idea, or directly from the command line.

What is the expected behaviour in such case?
Because i would expect the ssh client to close the connection, which should then also destroy the process that was spawned from it.

Build.gradle

tasks.register('runOnRemote') {
  group 'build'
  doLast {
    ssh.run {
      session(remotes.dev) {
        execute "cd TEST && java test.java" // TEST directory exists on remote
      }
    }
  }
}

test.java:
(simple program ta appends numbers to a file once per second)

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
class Main {
  public static void main(String[] args) throws Exception {
    final int[] c = { 0 };
    final var file = Paths.get("out"); // expecting empty file at start
    new Thread(() ->
    {
      while(true)
      {
        final var line = (c[0]++) + System.lineSeparator();
        try { Files.write(file, line.getBytes(), StandardOpenOption.APPEND); Thread.sleep(1000);}
        catch (Exception e) { throw new RuntimeException(e); }
      }
    }).start();
  }
}

After quitting the gradle task mid-execution, and inspecting the file "out" log file, the program keeps printing.
I can see the process with $ glances, and must shut it down manually.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the build.gradle reproduction, especially ssh.run, session, and execute, then run the task and interrupt it with CTRL+C while observing the remote test.java process and its out file. Determine the expected lifecycle of the SSH connection and spawned process; done means the interruption behavior is defined and the remote process no longer continues unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
build-system, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.