From 1fdc96cf0199fb21485b522629d505ee761394f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kornefalk?= Date: Thu, 5 Oct 2017 15:39:32 +0200 Subject: [PATCH] [#15] Writing data on closed socket causes unnecessary exception --- .../java/com/cloudhopper/smpp/impl/DefaultSmppSession.java | 5 +++++ .../com/cloudhopper/smpp/impl/DefaultSmppServerTest.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cloudhopper/smpp/impl/DefaultSmppSession.java b/src/main/java/com/cloudhopper/smpp/impl/DefaultSmppSession.java index c4975890..5896ab45 100644 --- a/src/main/java/com/cloudhopper/smpp/impl/DefaultSmppSession.java +++ b/src/main/java/com/cloudhopper/smpp/impl/DefaultSmppSession.java @@ -507,6 +507,11 @@ public WindowFuture sendRequestPdu(PduRequest pd } } + if (!this.channel.isOpen()) { + logger.info("Channel closed."); + return future; + } + // write the pdu out & wait timeout amount of time ChannelFuture channelFuture = this.channel.writeAndFlush(buffer); if (configuration.getWriteTimeout() > 0){ diff --git a/src/test/java/com/cloudhopper/smpp/impl/DefaultSmppServerTest.java b/src/test/java/com/cloudhopper/smpp/impl/DefaultSmppServerTest.java index 9963d1bb..ab51f681 100644 --- a/src/test/java/com/cloudhopper/smpp/impl/DefaultSmppServerTest.java +++ b/src/test/java/com/cloudhopper/smpp/impl/DefaultSmppServerTest.java @@ -461,8 +461,9 @@ public void serverSessionTimesOutWithNoBindRequest() throws Exception { try { BaseBindResp bindResponse = session0.bind(bindRequest, 200); Assert.fail(); - } catch (SmppChannelException e) { + } catch (SmppTimeoutException e) { // correct behavior + logger.debug("Got expected timeout exception {}", e.getMessage()); } // verify everything after the session timed out