Skip to content

Commit

Permalink
implement workaround for EstablishedContextStub being closed (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
kortemik authored Jun 25, 2024
1 parent 99ca9e6 commit 5ec838a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ public interface EstablishedContext extends Context {
* @return Egress of the connection for sending egress data.
*/
Egress egress();

boolean isStub();
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@ public Ingress ingress() {
public Egress egress() {
return egress;
}

@Override
public boolean isStub() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,10 @@ public Ingress ingress() {
public Egress egress() {
throw new IllegalArgumentException("EstablishedContextStub does not implement this");
}

@Override
public boolean isStub() {
return true;
}

}
8 changes: 6 additions & 2 deletions src/main/java/com/teragrep/net_01/eventloop/EventLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,17 @@ else if (selectionKey.isConnectable()) {
establishedContext.handleEvent(selectionKey);
}
catch (CancelledKeyException cke) {
establishedContext.close();
if (!establishedContext.isStub()) {
establishedContext.close();
}
throw cke;

}
}
}
catch (CancelledKeyException cke) {
LOGGER.warn("SocketPoll.poll CancelledKeyException caught: <{}>", cke.getMessage());
// TODO implement better exception handling in ConnectContext, ListenContext and EstablishedContext
LOGGER.warn("Detected unexpectedly closed channel");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ public Ingress ingress() {
public Egress egress() {
return egress;
}

@Override
public boolean isStub() {
return false;
}

}

0 comments on commit 5ec838a

Please sign in to comment.