Skip to content

Commit

Permalink
[JENKINS-36871] Allow a filter to call completed() from both the re…
Browse files Browse the repository at this point in the history
…ceive and send sides without bombing out.

Prevents stack traces such as

```
Exception in thread "main" java.lang.IllegalStateException: Filter has already been completed
	at org.jenkinsci.remoting.protocol.FilterLayer.completed(FilterLayer.java:106)
	at org.jenkinsci.remoting.protocol.impl.ConnectionHeadersFilterLayer.complete(ConnectionHeadersFilterLayer.java:365)
	at org.jenkinsci.remoting.protocol.impl.ConnectionHeadersFilterLayer.doSend(ConnectionHeadersFilterLayer.java:498)
	at org.jenkinsci.remoting.protocol.ProtocolStack$Ptr.doSend(ProtocolStack.java:691)
	at org.jenkinsci.remoting.protocol.ApplicationLayer.write(ApplicationLayer.java:157)
	at org.jenkinsci.remoting.protocol.impl.ChannelApplicationLayer.start(ChannelApplicationLayer.java:226)
	at org.jenkinsci.remoting.protocol.ProtocolStack.init(ProtocolStack.java:202)
	at org.jenkinsci.remoting.protocol.ProtocolStack.access$700(ProtocolStack.java:107)
	at org.jenkinsci.remoting.protocol.ProtocolStack$Builder.build(ProtocolStack.java:555)
	at org.jenkinsci.remoting.engine.JnlpProtocol4PlainHandler.connect(JnlpProtocol4PlainHandler.java:149)
	at org.jenkinsci.remoting.engine.JnlpProtocolHandler.connect(JnlpProtocolHandler.java:140)
	at org.jenkinsci.remoting.engine.HandlerLoopbackLoadStress.startClient(HandlerLoopbackLoadStress.java:466)
	at org.jenkinsci.remoting.engine.HandlerLoopbackLoadStress.main(HandlerLoopbackLoadStress.java:426)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
```
  • Loading branch information
stephenc committed Aug 5, 2016
1 parent 4bc69f2 commit 75c4cf7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -102,7 +102,7 @@ protected final void completed() {
LOGGER.log(Level.FINEST, "[{0}] Completed", stack().name());
}
synchronized (this) {
if (completionState != 0) {
if (completionState == 7) {
throw new IllegalStateException("Filter has already been completed");
}
completionState |= 1;
Expand Down
Expand Up @@ -749,15 +749,15 @@ public ProtocolStack<?> stack() {
public void remove() {
stackLock.readLock().lock();
try {
if (removed) {
return;
}
if (nextSend == null) {
throw new UnsupportedOperationException("Network layer is not supposed to call remove");
}
if (nextRecv == null) {
throw new UnsupportedOperationException("Application layer is not supposed to call remove");
}
if (removed) {
return;
}
// we just want to have a lock, we abuse the read lock here as the readers are eventually consistent
removed = true;
} finally {
Expand Down

0 comments on commit 75c4cf7

Please sign in to comment.