db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r707591 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net: ReplicationMessageReceive.java SocketConnection.java
Date Fri, 24 Oct 2008 09:52:05 GMT
Author: kahatlen
Date: Fri Oct 24 02:52:05 2008
New Revision: 707591

URL: http://svn.apache.org/viewvc?rev=707591&view=rev
Log:
DERBY-3878: Replication: stopSlave does not close serversocket when master has crashed

Use try/finally to ensure that the sockets are closed when closing the
socket streams fails.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java?rev=707591&r1=707590&r2=707591&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
Fri Oct 24 02:52:05 2008
@@ -209,11 +209,18 @@
             sendPingSemaphore.notify();
         }
 
-        if (socketConn != null) {
-            socketConn.tearDown();
-        }
-        if (serverSocket != null) {
-            serverSocket.close();
+        // socketConn.tearDown() may fail if the master has crashed. We still
+        // want to close the server socket if an exception is thrown, so that
+        // we don't prevent starting a new slave listening to the same port.
+        // Therefore, use try/finally. DERBY-3878
+        try {
+            if (socketConn != null) {
+                socketConn.tearDown();
+            }
+        } finally {
+            if (serverSocket != null) {
+                serverSocket.close();
+            }
         }
     }
     

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java?rev=707591&r1=707590&r2=707591&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java
Fri Oct 24 02:52:05 2008
@@ -110,8 +110,15 @@
      *                     the socket or the streams.
      */
     public void tearDown() throws IOException {
-        objInputStream.close();
-        objOutputStream.close();
-        socket.close();
+        // If the other party has crashed, closing the streams may fail (at
+        // least the output stream since its close() method calls flush()).
+        // In any case, we want the socket to be closed, so close it in a
+        // finally clause. DERBY-3878
+        try {
+            objInputStream.close();
+            objOutputStream.close();
+        } finally {
+            socket.close();
+        }
     }
 }



Mime
View raw message