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

[JENKINS-45233] - Log errors when Response message cannot be delivered due to the closed channel #177

Merged
merged 4 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/java/hudson/remoting/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,18 @@ protected Channel(@Nonnull ChannelBuilder settings, @Nonnull CommandTransport tr
transport.setup(this, new CommandReceiver() {
public void handle(Command cmd) {
commandsReceived++;
lastCommandReceivedAt = System.currentTimeMillis();
if (logger.isLoggable(Level.FINE))
long receivedAt = System.currentTimeMillis();
lastCommandReceivedAt = receivedAt;
if (logger.isLoggable(Level.FINE)) {
logger.fine("Received " + cmd);
} else if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "Received command " + cmd, cmd.createdAt);
}
try {
cmd.execute(Channel.this);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Completed command {0}. It took {1}ms", new Object[] {cmd, System.currentTimeMillis() - receivedAt});
}
} catch (Throwable t) {
logger.log(Level.SEVERE, "Failed to execute command " + cmd + " (channel " + Channel.this.name + ")", t);
logger.log(Level.SEVERE, "This command is created here", cmd.createdAt);
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/hudson/remoting/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.IOException;
import java.io.Serializable;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -346,13 +347,17 @@ public void run() {
rsp.createdAt.initCause(createdAt);

synchronized (channel) {// expand the synchronization block of the send() method to a check
Copy link
Member

Choose a reason for hiding this comment

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

comment implies this should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

right

if(!channel.isOutClosed())
if(!channel.isOutClosed()) {
Copy link
Member

Choose a reason for hiding this comment

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

arguably easier to read if test is inverted

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually the check is not required at all. Channel#send() does the check

channel.send(rsp);
} else {
// Propagate exception to the catch clause instead of supressing it
Copy link
Member

Choose a reason for hiding this comment

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

typo

throw new ClosedChannelException();
Copy link
Member

Choose a reason for hiding this comment

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

Is there a known cause here?

}
}
} catch (IOException e) {
// communication error.
// this means the caller will block forever
logger.log(Level.SEVERE, "Failed to send back a reply",e);
logger.log(Level.SEVERE, "Failed to send back a reply to the request " + this, e);
Copy link
Member

Choose a reason for hiding this comment

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

BTW SEVERE is probably excessive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I would also drop it to WARNING

} finally {
channel.executingCalls.remove(id);
Thread.currentThread().setName(oldThreadName);
Expand Down