Return-Path: Delivered-To: apmail-geronimo-activemq-dev-archive@www.apache.org Received: (qmail 74423 invoked from network); 26 Oct 2006 06:31:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Oct 2006 06:31:44 -0000 Received: (qmail 738 invoked by uid 500); 24 Oct 2006 10:05:15 -0000 Delivered-To: apmail-geronimo-activemq-dev-archive@geronimo.apache.org Received: (qmail 716 invoked by uid 500); 24 Oct 2006 10:05:15 -0000 Mailing-List: contact activemq-dev-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-dev@geronimo.apache.org Received: (qmail 707 invoked by uid 99); 24 Oct 2006 10:05:15 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Oct 2006 03:05:15 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Oct 2006 03:05:01 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id E6EBE7142C3 for ; Tue, 24 Oct 2006 03:04:02 -0700 (PDT) Message-ID: <3487016.1161684242943.JavaMail.root@brutus> Date: Tue, 24 Oct 2006 03:04:02 -0700 (PDT) From: "Rob Lugt (JIRA)" To: activemq-dev@geronimo.apache.org Subject: [jira] Assigned: (AMQ-988) Thread synchronization error in TcpTransport In-Reply-To: <1396809.1161159978816.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/activemq/browse/AMQ-988?page=all ] Rob Lugt reassigned AMQ-988: ---------------------------- Assignee: james strachan (was: Rob Lugt) Hi James. Please review and apply supplied patch. > Thread synchronization error in TcpTransport > -------------------------------------------- > > Key: AMQ-988 > URL: https://issues.apache.org/activemq/browse/AMQ-988 > Project: ActiveMQ > Issue Type: Bug > Components: NMS (C# client) > Affects Versions: 4.0.2 > Environment: Windows > Reporter: Rob Lugt > Assigned To: james strachan > Fix For: 4.1 > > Attachments: amq988-patch.txt > > > I have a problem where my C# client application crashes when placed under load. It's taken a while to get to the bottom of it, but I believe I have identified the problem and luckily there's a simple solution. > The AMQ .Net client uses a common pattern where a full-duplex TCP/IP connection is established with the broker, and the client uses two threads to concurrently read and write data to/from the underlying socket - one thread reading from a Reader object and the other writing to a Writer object. > The TcpTransport.Start() method contains the following:- > NetworkStream networkStream = new NetworkStream(socket); > socketWriter = new OpenWireBinaryWriter(networkStream); > socketReader = new OpenWireBinaryReader(networkStream); > This pattern is explicitly allowed in Java and Win32 applications, but .Net is a little vague on the subject. The Microsoft documentation [1] suggests use of the asynchronous read/write calls for multithreaded applications, but that would significantly complicate the C# client which relies on blocking stream behaviour. On the same doc page > Microsoft does specifiy that the Socket class is thread-safe, which I take to mean that concurrent read/write calls are permitted, however the same is not true of NetworkStream [2]. > Perhaps it would be reasonable to expect NetworkStream to have no internal state other than the Socket it contains, but apparently this is not the case because I've identified that it is a corrupt NetworkStream which is causing my application to crash under load. After some experimentation and a fair amount of load testing, I think the solution is a simple change to the TcpTransport.start() method to use a separate NetworkStream for input and output operations. e.g. :- > NetworkStream inputNetworkStream = new NetworkStream(socket); > NetworkStream outputNetworkStream = new NetworkStream(socket); > socketWriter = new OpenWireBinaryWriter(inputNetworkStream); > socketReader = new OpenWireBinaryReader(outputNetworkStream); > This works for me and my test client has now been running for 16 hours without crashing (before it would rarely last longer than 10 minutes). > Regards > Rob Lugt > [1] http://msdn2.microsoft.com/en-us/library/system.net.sockets.socket.aspx > [2] http://msdn2.microsoft.com/en-us/library/system.net.sockets.networkstream.aspx -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira