Author: norman
Date: Sun Apr 11 13:42:05 2010
New Revision: 932897
URL: http://svn.apache.org/viewvc?rev=932897&view=rev
Log:
Make sure we really dispose stuff, even on exceptions..
Modified:
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
Modified:
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java?rev=932897&r1=932896&r2=932897&view=diff
==============================================================================
---
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java
(original)
+++
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java
Sun Apr 11 13:42:05 2010
@@ -27,10 +27,12 @@ import org.apache.james.protocols.api.Li
import org.apache.james.protocols.api.ProtocolHandlerChain;
import org.apache.james.protocols.api.ProtocolSession;
import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
@@ -95,11 +97,28 @@ public abstract class AbstractChannelUps
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
- attributes.remove(ctx.getChannel());
+ cleanup(ctx.getChannel());
+
super.channelClosed(ctx, e);
}
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
+ cleanup(ctx.getChannel());
+
+ super.exceptionCaught(ctx, e);
+ }
+
+ private void cleanup(Channel channel) {
+ ProtocolSession session = (ProtocolSession) attributes.get(channel);
+ if (session != null) {
+ session.resetState();
+ session = null;
+ attributes.remove(channel);
+ }
+ }
+
/**
* Create a new "protocol" session
*
Modified:
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java?rev=932897&r1=932896&r2=932897&view=diff
==============================================================================
---
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
(original)
+++
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
Sun Apr 11 13:42:05 2010
@@ -36,24 +36,31 @@ public class SMTPChannelUpstreamHandler
@Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
logger.info("Dispose objects while closing channel " +
ctx.getChannel().getId());
- // Make sure we dispose everything on exit on session close
- SMTPSession smtpSession = (SMTPSession)
attributes.get(ctx.getChannel());
-
- if (smtpSession != null) {
-
LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.MAIL));
-
LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE));
-
LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_OUTPUTSTREAM));
- }
+ cleanup(ctx.getChannel());
super.channelDisconnected(ctx, e);
}
+
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
Channel channel = ctx.getChannel();
if (channel.isConnected()) {
ctx.getChannel().write(new SMTPResponse(SMTPRetCode.LOCAL_ERROR,
"Unable to process smtp request"));
}
+ cleanup(channel);
+ channel.close();
+ super.exceptionCaught(ctx, e);
}
+ private void cleanup(Channel channel) {
+ // Make sure we dispose everything on exit on session close
+ SMTPSession smtpSession = (SMTPSession) attributes.get(channel);
+
+ if (smtpSession != null) {
+
LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.MAIL));
+
LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE));
+
LifecycleUtil.dispose(smtpSession.getState().get(SMTPConstants.DATA_MIMEMESSAGE_OUTPUTSTREAM));
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]