Return-Path: X-Original-To: apmail-etch-commits-archive@www.apache.org Delivered-To: apmail-etch-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E9AC410BD6 for ; Tue, 18 Mar 2014 13:32:48 +0000 (UTC) Received: (qmail 39105 invoked by uid 500); 18 Mar 2014 13:32:48 -0000 Delivered-To: apmail-etch-commits-archive@etch.apache.org Received: (qmail 39059 invoked by uid 500); 18 Mar 2014 13:32:45 -0000 Mailing-List: contact commits-help@etch.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@etch.apache.org Delivered-To: mailing list commits@etch.apache.org Received: (qmail 39048 invoked by uid 99); 18 Mar 2014 13:32:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Mar 2014 13:32:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Mar 2014 13:32:43 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6AC81238897A; Tue, 18 Mar 2014 13:32:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1578869 - in /etch/trunk/binding-cpp: compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/ runtime/include/support/ runtime/src/main/support/ runtime/src/main/transport/ Date: Tue, 18 Mar 2014 13:32:23 -0000 To: commits@etch.apache.org From: veithm@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140318133223.6AC81238897A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: veithm Date: Tue Mar 18 13:32:22 2014 New Revision: 1578869 URL: http://svn.apache.org/r1578869 Log: ETCH-287 Fixing deadlock while calling methods on client side On calls getResult(), hasResult(), getException() or hasException() on a AsyncResult object the client waits until it gets notified from the mailbox that a respective message has arrived. In case the connection on socket level was broken before or during a method call the AsyncResult object was not notified about this error state and blocked forever. Change-Id: I511e2fc60eb8b347a0d184cc02a7fd3ec937f2b6 Modified: etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp Modified: etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm?rev=1578869&r1=1578868&r2=1578869&view=diff ============================================================================== --- etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm (original) +++ etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm Tue Mar 18 13:32:22 2014 @@ -52,8 +52,10 @@ status_t $clname::$n.name()AsyncResultRe capu::SmartPointer result; status = mBase->endcall(mb, $vfname::$n.getResultMessage().vname($helper), result); if(status != ETCH_OK) { - // TODO set result to a runtime exception - return ETCH_OK; + capu::SmartPointer exception = new EtchRuntimeException("Error occured while reading peers answer from mailbox for call $n.name() ", ETCH_ERROR); + setException(capu::smartpointer_cast(exception)); + mMailbox = NULL; + return ETCH_ERROR; } //result is NULL if it was a void call and no exception has been set @@ -68,10 +70,13 @@ status_t $clname::$n.name()AsyncResultRe #end } else { setMailboxStatus(); - } - - - } + } + } else { + //mailbox has been closed without answer from peer + capu::SmartPointer exception = new EtchRuntimeException("Peer did not answer in time to call $n.name()", ETCH_TIMEOUT); + setException(capu::smartpointer_cast(exception)); + mMailbox = NULL; +} #end return ETCH_OK; @@ -83,7 +88,10 @@ $intfname::$n.name()AsyncResultPtr $clna capu::SmartPointer msg; status = base->newMessage($vfname::$n.vname( $helper ), &msg); if(status != ETCH_OK) { - // TODO log error + $n.name()AsyncResultRemote* result = new $n.name()AsyncResultRemote(base, NULL); + capu::SmartPointer exception = new EtchRuntimeException("Unable to create message for call $n.name().", status); + result->setException(capu::smartpointer_cast(exception)); + return result; } #set($ObjCount = 0) @@ -95,11 +103,14 @@ $intfname::$n.name()AsyncResultPtr $clna EtchMailbox* mb = NULL; status = base->begincall(msg, mb); + $n.name()AsyncResultRemote* result = new $n.name()AsyncResultRemote(base, mb); + if(status != ETCH_OK) { - // TODO log error + //mailbox has been closed during send + capu::SmartPointer exception = new EtchRuntimeException("Unable to call $n.name() as connection has been closed by peer.", status); + result->setException(capu::smartpointer_cast(exception)); } - $n.name()AsyncResultRemote* result = new $n.name()AsyncResultRemote(base, mb); return result; } Modified: etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h?rev=1578869&r1=1578868&r2=1578869&view=diff ============================================================================== --- etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h (original) +++ etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h Tue Mar 18 13:32:22 2014 @@ -70,7 +70,7 @@ public: * Closes the mailbox so that no more messages can be delivered. * Queued messages remain to be read. */ - virtual status_t closeDelivery() = 0; + virtual status_t closeDelivery(capu::bool_t withNotification = true) = 0; /** * Closes the mailbox so that no more messages will be delivered or Modified: etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h?rev=1578869&r1=1578868&r2=1578869&view=diff ============================================================================== --- etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h (original) +++ etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h Tue Mar 18 13:32:22 2014 @@ -73,7 +73,7 @@ public: * @param true if this call closed the mailbox (that is, if action was * taken), false if the mailbox was already closed. */ - status_t closeDelivery(); + status_t closeDelivery(capu::bool_t withNotification = true); /** * Closes the mailbox so that no more messages will be delivered or Modified: etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp?rev=1578869&r1=1578868&r2=1578869&view=diff ============================================================================== --- etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp (original) +++ etch/trunk/binding-cpp/runtime/src/main/support/EtchAsyncResultNone.cpp Tue Mar 18 13:32:22 2014 @@ -31,7 +31,7 @@ EtchAsyncResultNone::EtchAsyncResultNone EtchAsyncResultNone::~EtchAsyncResultNone() { if(mMailbox != NULL) { mMailbox->unregisterNotify(this); - mMailbox->closeDelivery(); + mMailbox->closeDelivery(false); delete mMailbox; } } Modified: etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp?rev=1578869&r1=1578868&r2=1578869&view=diff ============================================================================== --- etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp (original) +++ etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp Tue Mar 18 13:32:22 2014 @@ -91,7 +91,7 @@ status_t EtchPlainMailbox::read(EtchMail return ETCH_ERROR; } -status_t EtchPlainMailbox::closeDelivery() { +status_t EtchPlainMailbox::closeDelivery(capu::bool_t withNotification) { mMutex.lock(); if(mQueue.isClosed()) { @@ -103,12 +103,15 @@ status_t EtchPlainMailbox::closeDelivery mQueue.close(); mMutex.unlock(); - fireNotify(); + if (withNotification) { + fireNotify(); + } + return ETCH_OK; } status_t EtchPlainMailbox::closeRead() { - if (closeDelivery() == ETCH_OK) { + if (closeDelivery(false) == ETCH_OK) { EtchMailbox::EtchElement* mbe = NULL; while ((read(mbe)) == ETCH_OK) { mMailboxManager->redeliver(mbe->mSender, mbe->mMsg); Modified: etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp?rev=1578869&r1=1578868&r2=1578869&view=diff ============================================================================== --- etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp (original) +++ etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp Tue Mar 18 13:32:22 2014 @@ -26,14 +26,18 @@ EtchPlainMailboxManager::EtchPlainMailbo } EtchPlainMailboxManager::~EtchPlainMailboxManager() { + mMutex.lock(); + EtchHashTable::Iterator it = mMailboxes.begin(); EtchHashTable::HashTableEntry entry; - // TODO check thread safety + while (it.hasNext()) { it.next(&entry); entry.value->closeDelivery(); delete entry.value; } + + mMutex.unlock(); } EtchTransportMessage* EtchPlainMailboxManager::getTransport() { @@ -51,20 +55,16 @@ status_t EtchPlainMailboxManager::regist const EtchLong msgid = mb->getMessageId(); - mMutex.lock(); if (!mUp) { - mMutex.unlock(); return ETCH_EINVAL; } EtchMailbox* tmp = NULL; if (mMailboxes.get(msgid, &tmp) != ETCH_ENOT_EXIST) { - mMutex.unlock(); return ETCH_EINVAL; } mMailboxes.put(msgid, mb); - mMutex.unlock(); ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "A new mailbox is registered"); return ETCH_OK; } @@ -119,19 +119,23 @@ status_t EtchPlainMailboxManager::transp ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "A mailbox has been created for msgid " << msgid); EtchMailbox *mb = new EtchPlainMailbox(this, msgid); + mMutex.lock(); if (registerMailbox(mb) != ETCH_OK) { delete mb; ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Mailbox registration failed"); + mMutex.unlock(); return ETCH_ERROR; } ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Message sending to Messagizer and registering a respective mailbox"); if (mTransport->transportMessage(recipient, msg) == ETCH_OK) { result = mb; + mMutex.unlock(); return ETCH_OK; } else { - unregisterMailbox(mb); + mb->closeDelivery(); delete mb; + mMutex.unlock(); return ETCH_ERROR; } } @@ -173,12 +177,12 @@ status_t EtchPlainMailboxManager::sessio } status_t EtchPlainMailboxManager::sessionNotify(capu::SmartPointer event) { + mMutex.lock(); if (event->equals(&EtchSession::UP())) { mUp = true; ETCH_LOG_TRACE(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Connection is up"); } else if (event->equals(&EtchSession::DOWN())) { mUp = false; - // TODO check thread safety EtchHashTable::Iterator it = mMailboxes.begin(); EtchHashTable::HashTableEntry entry; while (it.hasNext()) { @@ -188,6 +192,8 @@ status_t EtchPlainMailboxManager::sessio } ETCH_LOG_TRACE(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Connection is down"); } + mMutex.unlock(); + status_t status; if(mSession != NULL) { status = mSession->sessionNotify(event);