Skip to content
Permalink
Browse files
[FIXED JENKINS-20769]
When ProxyWriter is finalized, it should attempt to release a remote reference count,
but it shouldn't try to close the stream. For one, the other side that had exported
the writer might be still using it (imagine exporting System.out), and secondly, the
said object could have already been unexported, for example if the closure that brought
ProxyWriter to this side has already returned, since RemoteWriter is auto-unexporting.

Compare ProxyOutputStream impl vs ProxyWriter impl and the difference becomes clearer.
  • Loading branch information
kohsuke committed Mar 27, 2014
1 parent 20db12d commit 96c670de534de269bcde729a932655842a3aea2a
Showing with 38 additions and 1 deletion.
  1. +1 −0 src/main/java/hudson/remoting/ProxyOutputStream.java
  2. +37 −1 src/main/java/hudson/remoting/ProxyWriter.java
@@ -196,6 +196,7 @@ private void doClose(Throwable error) throws IOException {
protected void finalize() throws Throwable {
super.finalize();
// if we haven't done so, release the exported object on the remote side.
// if the object is auto-unexported, the export entry could have already been removed.
if(channel!=null) {
channel.send(new Unexport(channel.newIoId(),oid));
channel = null;
@@ -129,7 +129,13 @@ public synchronized void close() throws IOException {

protected void finalize() throws Throwable {
super.finalize();
close();
// if we haven't done so, release the exported object on the remote side.
// if the object is auto-unexported, the export entry could have already been removed.
if(channel!=null) {
channel.send(new Unexport(channel.newIoId(),oid));
channel = null;
oid = -1;
}
}

/**
@@ -186,4 +192,34 @@ public String toString() {

private static final long serialVersionUID = 1L;
}

/**
* {@link Command} for releasing an export table.
*
* <p>
* Unlike {@link EOF}, this just unexports but not closes the stream.
*/
private static class Unexport extends Command {
private final int oid;
private final int ioId;

public Unexport(int ioId, int oid) {
this.ioId = ioId;
this.oid = oid;
}

protected void execute(final Channel channel) {
channel.pipeWriter.submit(ioId,new Runnable() {
public void run() {
channel.unexport(oid);
}
});
}

public String toString() {
return "Pipe.Unexport("+oid+")";
}

private static final long serialVersionUID = 1L;
}
}

1 comment on commit 96c670d

@jglick
Copy link
Member

@jglick jglick commented on 96c670d Mar 27, 2014

Choose a reason for hiding this comment

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

BTW commit comment should started with [JENKINS-20769] rather than [FIXED JENKINS-20769] since the JIRA link daemon is not smart enough to know that the new version has to be integrated into jenkinsci/jenkins for the fix to take effect.

Please sign in to comment.