[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207198528
 
 

 ##
 File path: 
plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcConnectionIT.java
 ##
 @@ -58,7 +58,12 @@ public void setUp() {
 @After
 public void tearDown() {
 if(s7PlcConnection.isConnected()) {
-s7PlcConnection.close();
+try {
+s7PlcConnection.close();
+} catch (NullPointerException e) {
 
 Review comment:
   apparently blocking operations are not allowed (`await()`)


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207197726
 
 

 ##
 File path: 
plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/connection/S7PlcConnectionIT.java
 ##
 @@ -58,7 +58,12 @@ public void setUp() {
 @After
 public void tearDown() {
 if(s7PlcConnection.isConnected()) {
-s7PlcConnection.close();
+try {
+s7PlcConnection.close();
+} catch (NullPointerException e) {
 
 Review comment:
   route cause of failing test is 
`io.netty.util.concurrent.BlockingOperationException` and only NPE gets caught 
so the test still fails


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207148665
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
+channel.closeFuture().await(1_000);
+} catch (InterruptedException e) {
+logger.warn("Connection was not closed by PLC, has to be 
closed from driver side now.", e);
+} finally {
+// close the session itself.
 channel.eventLoop().parent().shutdownGracefully();
 
 Review comment:
   One thing to note here. If we put this in the finally blog  a potential 
thrown exception is omitted. Especially as the method is called `gracefully`. I 
would suggest to put it outside a finally or wrap it with a try catch ignore.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207149145
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
+channel.closeFuture().await(1_000);
+} catch (InterruptedException e) {
+logger.warn("Connection was not closed by PLC, has to be 
closed from driver side now.", e);
+} finally {
+// close the session itself.
 channel.eventLoop().parent().shutdownGracefully();
 
 Review comment:
   example code: 
   ```
   try {
   try {
   throw new RuntimeException("Important information");
   } finally {
   throw new OutOfMemoryError("Something failed gracefully");
   }
   } catch (Throwable e) {
   assert e.class == OutOfMemoryError.class;
   }
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] sruehl commented on a change in pull request #10: Fixed NPE in S7PlcConnection#close.

2018-08-02 Thread GitBox
sruehl commented on a change in pull request #10: Fixed NPE in 
S7PlcConnection#close.
URL: https://github.com/apache/incubator-plc4x/pull/10#discussion_r207145613
 
 

 ##
 File path: 
plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 ##
 @@ -183,14 +194,19 @@ public void close() {
 (short) 0x, (short) 0x000F, DisconnectReason.NORMAL, 
Collections.emptyList(),
 null);
 ChannelFuture sendDisconnectRequestFuture = 
channel.writeAndFlush(disconnectRequest);
-sendDisconnectRequestFuture.addListener((ChannelFutureListener) 
future -> {
-// Close the session itself.
-channel.closeFuture().await();
+// Wait if the PLC closes the connection
+try {
+// TODO 02.08.18 jf: Do we have global constants for things 
like timeouts?
+channel.closeFuture().await(1_000);
+} catch (InterruptedException e) {
+logger.warn("Connection was not closed by PLC, has to be 
closed from driver side now.", e);
 
 Review comment:
   Here we should add a `Thread.currentThread().interrupt();` after the 
logging. (Sonar would tell you this later anyway ;)


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services