Don't try to send Notify message if the session
has been closed externally
Change-Id: Idd57bd5bf60e4f758ed0187bd12149854740cd36
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
(cherry picked from commit
14cad280a7d1ba51f72d683e689eb3b2eca96909)
@Override
public void onSessionDown(final BGPSession session, final Exception e) {
@Override
public void onSessionDown(final BGPSession session, final Exception e) {
- LOG.info("Session with peer {} went down", this.name, e);
+ if(e.getMessage().equals(BGPSessionImpl.END_OF_INPUT)) {
+ LOG.info("Session with peer {} went down", this.name);
+ } else {
+ LOG.info("Session with peer {} went down", this.name, e);
+ }
private static final int KA_TO_DEADTIMER_RATIO = 3;
private static final int KA_TO_DEADTIMER_RATIO = 3;
+ static final String END_OF_INPUT = "End of input detected. Close the session.";
+
/**
* Internal session state.
*/
/**
* Internal session state.
*/
@Override
public synchronized void close() {
@Override
public synchronized void close() {
- LOG.info("Closing session: {}", this);
-
- if (this.state != State.IDLE) {
+ if (this.state != State.IDLE && this.channel.isActive()) {
this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(
this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(
- BGPError.CEASE.getSubcode()).build());
- removePeerSession();
- this.channel.close();
- this.state = State.IDLE;
+ BGPError.CEASE.getSubcode()).build());
+ this.closeWithoutMessage();
public synchronized void endOfInput() {
if (this.state == State.UP) {
public synchronized void endOfInput() {
if (this.state == State.UP) {
- this.listener.onSessionDown(this, new IOException("End of input detected. Close the session."));
+ LOG.info(END_OF_INPUT);
+ this.listener.onSessionDown(this, new IOException(END_OF_INPUT));
}
private synchronized void closeWithoutMessage() {
}
private synchronized void closeWithoutMessage() {
- LOG.debug("Closing session: {}", this);
+ LOG.info("Closing session: {}", this);
removePeerSession();
this.channel.close();
this.state = State.IDLE;
removePeerSession();
this.channel.close();
this.state = State.IDLE;
}
}).when(this.speakerListener).writeAndFlush(any(Notification.class));
doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
}
}).when(this.speakerListener).writeAndFlush(any(Notification.class));
doReturn(this.eventLoop).when(this.speakerListener).eventLoop();
+ doReturn(true).when(this.speakerListener).isActive();
doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
doAnswer(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {