You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2008/10/24 11:52:05 UTC
svn commit: r707591 - in
/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/replication/net:
ReplicationMessageReceive.java SocketConnection.java
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();
+ }
}
}