Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-45023] - Prevent execution of commands on closed or beingClo…
…sed channels (#175) * [JENKINS-45023] - Prevent execution of commands on closed or beingClosed channels This is a major update of Request execution logic in remoting Channels, which should improve stability of the channel and prevent hanging of commands if the channel gets closed. - [x] - `Channel#close()` does not always wait of synchronization to happen. There is a sender status check before the lock gets acquired. TODO: find an issue for that - [x] - `Channel#isClosingOrClosed()` now returns `null` once the first `Channel#close()` command arrives, we do not even wait till it acquires the instance lock. The API is [used outside Remoting](https://github.com/search?q=org%3Ajenkinsci+isClosingOrClosed&type=Code), but it seems that the change is correct in that cases - [x] - `Channel#call()` and `Channel#callAsync()` now fail if the channel `isClosingOrClosed()`. These calls implement `UserRequest`, and I do not think there is a valid case for even trying any user-space request - [x] - Offer new API in `hudson.remoting.Request`, which allows checking the channel state before invoking a call. By default it just checks if the channel is closed (just “fail fast” without command initialization) - [x] - Implement the new API in `UserRequest`, to prevent low-level API calls on a channel, which `isClosingOrClosed()` * [JENKINS-45023] - Address Javadoc comments from @jglick * [JENKINS-45023] - Chanel#terminate() should also immediately set the closeRequested flag * [JENKINS-45023] - Use ChannelClosedException when channel is being closed and cannot accept commands * [JENKINS-45023] - Add functional tests for the deadlocked channel * [JENKINS-45023] - UserRequest constructor should not hang when the channel shutdown is pendind && the lock cannot be acquired
- Loading branch information
1 parent
47b20da
commit 67edc4b
Showing
6 changed files
with
341 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
package hudson.remoting; | ||
|
||
import java.io.IOException; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Indicates that the channel is already closed. | ||
* Indicates that the channel is already closed or being closed. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class ChannelClosedException extends IOException { | ||
/** | ||
* @deprecated | ||
* Use {@link #ChannelClosedException(Throwable)}. | ||
* Use {@link #ChannelClosedException(Throwable)} or {@link #ChannelClosedException(java.lang.String, java.lang.Throwable)}. | ||
* This constructor will not include cause of the termination. | ||
*/ | ||
@Deprecated | ||
public ChannelClosedException() { | ||
super("channel is already closed"); | ||
} | ||
|
||
public ChannelClosedException(Throwable cause) { | ||
super("channel is already closed"); | ||
initCause(cause); | ||
super("channel is already closed", cause); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param message Message | ||
* @param cause Cause of the channel close/termination. | ||
* May be {@code null} if it cannot be determined when the exception is constructed. | ||
* @since TODO | ||
*/ | ||
public ChannelClosedException(@Nonnull String message, @CheckForNull Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.