Seeing data corruption when using ChannelHandlerContext.set/getAttachement API

Greg Beeble beeblezap at gmail.com
Tue Jul 20 19:22:57 EDT 2010


I've tried this both on versions 3.1.5 as well as 3.2.1.

My use-case has hundreds of clients connected to a single server.  Each
client creates a "session" object when they first establish a connection
with my server.  I've been using ChannelHandlerContext.set/getAttachment API
to store my session info so I can subsequently retrieve it.   What I'm
seeing is the following:
1) Client X establishes connection, creates a "session" and stored as
attachment in ChannelHandlerContext
2) Client Y establishes connection...
3) More clients connect and push data to the server...time passes...
4) I see client X's data being sent to client Y's channel.  That is, when I
do a ChannelHandlerContext.getAttachment() inside messageReceived(...)
method -- I get back client X's data but the session belongs to client Y.  
I've also confirmed this by printing out the remoteAddress on the channel
object and it appears as though there is some kind of race condition in
respect to channel objects... not sure.. Help!


Here is my bit of my server code:

 public void start() {
        // Configure the server.
        ServerBootstrap bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));
        
        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.keepAlive", true);

        ChannelPipeline pipeline = bootstrap.getPipeline();

        // Add the text line codec combination first,
        pipeline.addLast("framer", new DelimiterBasedFrameDecoder(
                1024, Delimiters.lineDelimiter()));
        pipeline.addLast("decoder", new StringDecoder());
        pipeline.addLast("encoder", new StringEncoder());
        
        // Set up the default event pipeline.
        bootstrap.getPipeline().addLast("handler", new ServerHandler());

        // Bind and start to accept incoming connections.
        bootstrap.bind(new InetSocketAddress(_port));
        }catch(Exception e){
            s_logger.error(e);
        }
    }





Thanks,
Greg

My JVM: 
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6) (rhel-1.11.b16.el5-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

My OS: CentOS release 5.5 (Final)
Linux blah 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009
x86_64 x86_64 x86_64 GNU/Linux

-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Seeing-data-corruption-when-using-ChannelHandlerContext-set-getAttachement-API-tp5318952p5318952.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list