Bug 544149 - Hang when fetching when plink used for GIT_SSH
Summary: Hang when fetching when plink used for GIT_SSH
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.2   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-05 13:03 EST by Chad Nunemaker CLA
Modified: 2019-02-05 14:13 EST (History)
1 user (show)

See Also:


Attachments
Stacktrace for the hanging JGit process (6.18 KB, text/plain)
2019-02-05 13:03 EST, Chad Nunemaker CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chad Nunemaker CLA 2019-02-05 13:03:36 EST
Created attachment 277458 [details]
Stacktrace for the hanging JGit process

When attempting to fetch from a GitHub repo via jgit.sh version 5.2.1.201812262042-r using a GIT_SSH set to plink.exe, jgit seems to hang for a very long time before completing.

This seems very similar to this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=529463

The workaround of commenting out the code from that bug works for me as well.
Although that bug is marked as fixed, the fix implemented is different than what works for me.

Here is a snippet of the stacktrace during the hang (see attached for full trace):
"main" #1 prio=5 os_prio=0 cpu=484.38ms elapsed=59.32s tid=0x0000029c44d56800 nid=0x4154 in Object.wait()  [0x000000ea127fe000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(java.base@11.0.2/Native Method)
        - waiting on <0x0000000089d128a8> (a org.eclipse.jgit.util.io.StreamCopyThread)
        at java.lang.Thread.join(java.base@11.0.2/Thread.java:1313)
        - waiting to re-lock in wait() <0x0000000089d128a8> (a org.eclipse.jgit.util.io.StreamCopyThread)
        at org.eclipse.jgit.util.io.StreamCopyThread.halt(StreamCopyThread.java:94)
        at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.close(TransportGitSsh.java:319)
        at org.eclipse.jgit.transport.FetchProcess.closeConnection(FetchProcess.java:277)
        at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:195)
        at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:124)
        at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1271)
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:243)
        at org.eclipse.jgit.pgm.Fetch.run(Fetch.java:165)
        at org.eclipse.jgit.pgm.TextBuiltin.execute(TextBuiltin.java:264)
        at org.eclipse.jgit.pgm.Main.execute(Main.java:278)
        at org.eclipse.jgit.pgm.Main.run(Main.java:166)
        at org.eclipse.jgit.pgm.Main.main(Main.java:138)

Originally, this bug was discovered via Eclipse Git functions hanging and working backwards until it was discovered that JGit was likely the cause.
Comment 1 Thomas Wolf CLA 2019-02-05 14:13:56 EST
The basic problem is still that StreamCopyThread tries to stop reading from the
error stream by interrupting the reading thread. That just doesn't work.

Possibly explicitly closing the streams before destroying the process might help. Something like

  if (process != null) {
    try {
      process.getErrorStream().close();
    } catch (IOException e) {
      // Ignore
    }
    process.destroy();
  }

This assumes that the read() inside StreamCopyThread would then return with -1.