Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jgit push throwing org.eclipse.jgit.api.errors.TransportException: Connection reset #126

Open
bhasky-java opened this issue Jan 7, 2025 · 8 comments

Comments

@bhasky-java
Copy link

Version

7.0.0.202409031743-r

Operating System

Windows

Bug description

I am trying to push the branch to the remote repo as soon as after i create and checkout the branch. Here is the code i used. Please note fetch and pull works fine.

Ref ref = git.checkout.setCreateBranch(true).setName("testbranch1").setUpstreamMode(CreateBranchCommandMode.SET_UPSTREAM).
setStartPoint("origin/main").call();

System.out.println("Git Reference branch name:"+ref.getName();

Thread.sleep(10000);
git.push().setRemote("origin").add("testbranch1").setCrendentialsProvider(new UserNamePasswordCrendentialsProvider("test","test").call();

Actual behavior

jgit push is throwing connection reset error

Expected behavior

jgit should work fine.

Relevant log output

caused by: org.ecllipse.jgit.errors.TransportException: https://gihub.com/internal/test-project.git: Connection reset
        at org.eclipse.jgit.transport.BasePackPushConnection.doPush(BasePackPushConnection.java:206)
...............
Caused by: java.net.SocketException: Connection reset
	at java.base/sun.nio.ch.NioSocketImpl.implRead(Unknown Source)
	at java.base/sun.nio.ch.NioSocketImpl.read(Unknown Source)
	at java.base/sun.nio.ch.NioSocketImpl$1.read(Unknown Source)
	at java.base/java.net.Socket$SocketInputStream.read(Unknown Source)
	at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source)
	at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source)
	at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(Unknown Source)

Other information

No response

@bhasky-java
Copy link
Author

to add some more notes, we are accessing github repo behind the firewall, so i added below to set http and https proxy of the host and port before push and tried but still getting same error.

System.setProperty("http.proxyHost","host name");
System.setProperty("http.proxyPort","8080");
System.setProperty("https.proxyHost","host name");
System.setProperty("https.proxyPort","8080");

@tomaswolf
Copy link
Contributor

Impossible to say what's wrong with the little information you gave us. There are typos in the code and presumably in the exception trace ("gihub"), and the exception trace is not complete, and we don't know if there were any earlier exceptions that might be relevant.

We can only guess, but such guesses may be completely off since we don't have enough information. I'll venture one guess anyway: try using not the JDK HTTP client but the Apache HTTP client. The JDK does not allow connecting to an HTTPS server with Basic Authentication through a HTTP proxy.

@bhasky-java
Copy link
Author

sorry for typo, that is https://github.com/{our internal url}. I have attached snapshot. can you share some Apache HTTP client examples with jgit library.
Stack trace error_snapshot

@tomaswolf
Copy link
Contributor

can you share some Apache HTTP client examples with jgit library.

Look at the JGit tests. Basically you'll need to include bundle org.eclipse.jgit.http.apache in your application and then set the factory before making other JGit calls: HttpTransport.setConnectionFactory(new HttpClientConnectionFactory());

@bhasky-java
Copy link
Author

I have added as you suggested before push

HttpTransport.setConnectionFactory(new HttpClientConnectionFactory());
git.push().setRemote("origin").add("testbranch1").setCrendentialsProvider(new UserNamePasswordCrendentialsProvider("test","test").call();

I am getting error 407 407 Proxy Authentication Required, however i had already set proxy details like i shown above before jgit calls.

ProxyAuthenticationError

@bhasky-java
Copy link
Author

As i mentioned jgit pull and fetch are working with these setting proxy details only push is failing.

System.setProperty("http.proxyHost","host name");
System.setProperty("http.proxyPort","8080");
System.setProperty("https.proxyHost","host name");
System.setProperty("https.proxyPort","8080");

@tomaswolf
Copy link
Contributor

tomaswolf commented Jan 8, 2025

If you have a proxy that requires authentication you'll also need to set up an Authenticator that can provide the need auth details. Also note: for Github, the password should be a PAT as explained in the EGit documentation. "test" doesn't look like a PAT.

I don't know why only the push fails. Possibly the Github repository is set up to allow anonymous fetches, but requires authentication only for pushes.

You could also try to use Eclipse and see if EGit can do the push if you define the correct proxy settings, including proxy password, if any, in the Eclipse preferences. (Easiest way: install Eclipse, open the Git Repositories view, import an existing clone, make sure testbranch1 is checked out. Go to the preferences, make sure the proxy settings are correct, and choose "Apache HTTP" as HTTP client in the Version Control(Team)→Git preferences. Then choose "Push to origin" in the context menu of the repository in the Git Repositories view.)

I'm sorry we cannot help you much. If neither of the above suggestions help, you'll have to debug this yourself.

@bhasky-java
Copy link
Author

Yes, i am using PAT, "test"=PAT, git push origin testbranch1 works fine. I only have issue with jgit push. i tried all possible options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants