Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: jenkinsci/jenkins
...
head fork: jenkinsci/jenkins
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 07, 2011
Richard Mortimer oldelvet Flush HTTP input and error streams after searching for the X-Hudson-C…
…LI-Port

property. This releases the HTTP connection in a friendly way and allows the
webserver to recycle the connection a little quicker.
87995e9
Richard Mortimer oldelvet [FIXED JENKINS-11130] SEVERE: I/O error in channel Chunked connection…
… when using jenkins-cli.jar

When using HTTP full duplex connections the upstream channel can be idle for
long periods of time and the webserver will time the connection out. Jenkins
sees this and terminates the downstream channel causing the unexpected closure
of the read channel in the CLI client.

Timeout of 15 seconds is based on the 20 second default timeout as seen in
Ubuntu Oneiric Tomcat 6 installations.
92496f9
Showing with 32 additions and 1 deletion.
  1. +3 −0  changelog.html
  2. +29 −1 cli/src/main/java/hudson/cli/CLI.java
3  changelog.html
View
@@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
+ <li class=bug>
+ java.io.IOException: Unexpected termination of the channel - SEVERE: I/O error in channel Chunked connection when using jenkins-cli.jar (works on older Hudson version)
+ (<a href="https://issues.jenkins-ci.org/browse/JENKINS-11130">issue 11130</a>)
<li class=>
</ul>
</div><!--=TRUNK-END=-->
30 cli/src/main/java/hudson/cli/CLI.java
View
@@ -47,6 +47,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
@@ -121,7 +122,7 @@ private Channel connectViaHttp(String url) throws IOException {
FullDuplexHttpStream con = new FullDuplexHttpStream(jenkins);
Channel ch = new Channel("Chunked connection to "+jenkins,
pool,con.getInputStream(),con.getOutputStream());
- new PingThread(ch,30*1000) {
+ new PingThread(ch,15*1000) {
protected void onDead() {
// noop. the point of ping is to keep the connection alive
// as most HTTP servers have a rather short read time out
@@ -153,11 +154,38 @@ private int getCliTcpPort(String url) throws IOException {
throw (IOException)new IOException("Failed to connect to "+url).initCause(e);
}
String p = head.getHeaderField("X-Hudson-CLI-Port");
+ flushURLConnection(head);
if(p==null) return -1;
return Integer.parseInt(p);
}
/**
+ * Flush the supplied {@link URLConnection} input and close the
+ * connection nicely.
+ * @param conn the connection to flush/close
+ */
+ private void flushURLConnection(URLConnection conn) {
+ byte[] buf = new byte[1024];
+ try {
+ InputStream is = conn.getInputStream();
+ while (is.read(buf) > 0) {
+ // Ignore
+ }
+ is.close();
+ } catch (IOException e) {
+ try {
+ InputStream es = ((HttpURLConnection)conn).getErrorStream();
+ while (es.read(buf) > 0) {
+ // Ignore
+ }
+ es.close();
+ } catch (IOException ex) {
+ // Ignore
+ }
+ }
+ }
+
+ /**
* Shuts down the channel and closes the underlying connection.
*/
public void close() throws IOException, InterruptedException {

No commit comments for this range

Something went wrong with that request. Please try again.