Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-09-23 06:10:26 +0000
committerEike Stepper2010-09-23 06:10:26 +0000
commitf13252bac7c020a40e066c64ba836ab09c4835eb (patch)
treed9066184bfba9d5bbd9f0a171009c0daaa76d7af /plugins/org.eclipse.net4j.tcp
parent555f9751297fdfeab3d1a9bd3d03328977f82758 (diff)
downloadcdo-f13252bac7c020a40e066c64ba836ab09c4835eb.tar.gz
cdo-f13252bac7c020a40e066c64ba836ab09c4835eb.tar.xz
cdo-f13252bac7c020a40e066c64ba836ab09c4835eb.zip
[326021] Deadlock potential in TCPSelector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=326021
Diffstat (limited to 'plugins/org.eclipse.net4j.tcp')
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java39
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java2
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java40
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java4
4 files changed, 66 insertions, 19 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
index e0276eeaac..5926a16f39 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
@@ -156,7 +156,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
catch (Exception ex)
{
OM.LOG.error(ex);
- deactivate();
+ deactivateAsync();
}
finally
{
@@ -192,7 +192,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
}
catch (ClosedChannelException ex)
{
- deactivate();
+ deactivateAsync();
}
catch (Exception ex)
{
@@ -201,7 +201,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
OM.LOG.error(ex);
}
- deactivate();
+ deactivateAsync();
}
}
@@ -211,6 +211,11 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
return MessageFormat.format("TCPAcceptor[{0}:{1}]", address, port); //$NON-NLS-1$
}
+ protected TCPServerConnector createConnector()
+ {
+ return new TCPServerConnector(this);
+ }
+
@Override
protected void doBeforeActivate() throws Exception
{
@@ -248,12 +253,34 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
@Override
protected void doDeactivate() throws Exception
{
- serverSocketChannel.close();
+ cancelSelectionKey();
+
+ IOUtil.closeSilent(serverSocketChannel);
+ serverSocketChannel = null;
super.doDeactivate();
}
- protected TCPServerConnector createConnector()
+ protected void deactivateAsync()
{
- return new TCPServerConnector(this);
+ // Cancel the selection immediately
+ cancelSelectionKey();
+
+ // Do the rest of the deactivation asynchronously
+ getConfig().getReceiveExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ deactivate();
+ }
+ });
+ }
+
+ private void cancelSelectionKey()
+ {
+ if (selectionKey != null)
+ {
+ selectionKey.cancel();
+ selectionKey = null;
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
index d4c37fcb40..9ee821c59a 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
@@ -98,7 +98,7 @@ public class TCPClientConnector extends TCPConnector
catch (Exception ex)
{
OM.LOG.error(ex);
- deactivate();
+ deactivateAsync();
}
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
index 7271ae0d7b..08d085ffe9 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
@@ -189,7 +189,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
{
OM.LOG.error(ex);
setNegotiationException(ex);
- deactivate();
+ deactivateAsync();
}
catch (ClosedChannelException ex)
{
@@ -198,14 +198,14 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
TRACER.trace("Socket channel closed: " + socketChannel); //$NON-NLS-1$
}
- deactivate();
+ deactivateAsync();
}
catch (Exception ex)
{
if (isActive())
{
OM.LOG.error(ex);
- deactivate();
+ deactivateAsync();
}
}
}
@@ -279,14 +279,14 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
TRACER.trace("Socket channel closed: " + socketChannel); //$NON-NLS-1$
}
- deactivate();
+ deactivateAsync();
}
catch (Exception ex)
{
if (isActive())
{
OM.LOG.error(ex);
- deactivate();
+ deactivateAsync();
}
}
}
@@ -356,11 +356,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
@Override
protected void doDeactivate() throws Exception
{
- if (selectionKey != null)
- {
- selectionKey.cancel();
- selectionKey = null;
- }
+ cancelSelectionKey();
LifecycleUtil.deactivate(controlChannel);
controlChannel = null;
@@ -370,6 +366,30 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
super.doDeactivate();
}
+ protected void deactivateAsync()
+ {
+ // Cancel the selection immediately
+ cancelSelectionKey();
+
+ // Do the rest of the deactivation asynchronously
+ getConfig().getReceiveExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ deactivate();
+ }
+ });
+ }
+
+ private void cancelSelectionKey()
+ {
+ if (selectionKey != null)
+ {
+ selectionKey.cancel();
+ selectionKey = null;
+ }
+ }
+
private void checkSelectionKey()
{
if (selectionKey == null)
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
index 680a28a1c4..a43cdad553 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Eike Stepper - initial API and implementation
*/
@@ -88,7 +88,7 @@ public class TCPServerConnector extends TCPConnector
catch (Exception ex)
{
OM.LOG.error(ex);
- deactivate();
+ deactivateAsync();
}
}
}

Back to the top