db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r708173 - in /db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net: ReplicationMessageReceive.java SocketConnection.java
Date Mon, 27 Oct 2008 13:38:21 GMT
Author: kahatlen
Date: Mon Oct 27 06:38:20 2008
New Revision: 708173

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

Merged fix from trunk (revision 707591).

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

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java?rev=708173&r1=708172&r2=708173&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/ReplicationMessageReceive.java
Mon Oct 27 06:38:20 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/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java?rev=708173&r1=708172&r2=708173&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/store/replication/net/SocketConnection.java
Mon Oct 27 06:38:20 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