From 39d12d088ae3ad3ffb5e67647906f7cd6d8f794c Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 11 Jan 2013 20:37:08 -0800 Subject: [PATCH 1/3] use usleep when waiting for cref to be available --- xwords4/relay/crefmgr.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index 9adb5df07..61987c811 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "crefmgr.h" #include "cref.h" @@ -413,6 +414,8 @@ CRefMgr::getCookieRef( CookieID cid, bool failOk ) break; } m_cidlock->Relinquish( cinfo, true ); + logf( XW_LOGINFO, "%s: sleeping after failing to get cinfo", __func__ ); + usleep(200000); /* 2/10 second */ } return cinfo; } /* getCookieRef */ From 55514719be7978becb13abd213deffe8a9399404 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 11 Jan 2013 20:42:04 -0800 Subject: [PATCH 2/3] include thread ptr in hung threads logging; assert (restart) when hung for too long --- xwords4/relay/tpool.cpp | 16 ++++++++-------- xwords4/relay/tpool.h | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xwords4/relay/tpool.cpp b/xwords4/relay/tpool.cpp index b06e8aa3a..0d62b5d65 100644 --- a/xwords4/relay/tpool.cpp +++ b/xwords4/relay/tpool.cpp @@ -85,17 +85,15 @@ XWThreadPool::Setup( int nThreads, packet_func pFunc, kill_func kFunc ) m_pFunc = pFunc; m_kFunc = kFunc; - pthread_t thread; - - int ii; - for ( ii = 0; ii < nThreads; ++ii ) { + for ( int ii = 0; ii < nThreads; ++ii ) { ThreadInfo* tip = &m_threadInfos[ii]; tip->me = this; - int result = pthread_create( &thread, NULL, tpool_main, tip ); + int result = pthread_create( &tip->thread, NULL, tpool_main, tip ); assert( result == 0 ); - pthread_detach( thread ); + pthread_detach( tip->thread ); } + pthread_t thread; int result = pthread_create( &thread, NULL, listener_main, this ); assert( result == 0 ); result = pthread_detach( thread ); @@ -478,7 +476,7 @@ XWThreadPool::print_in_use( void ) void XWThreadPool::log_hung_threads( void ) { - const time_t HUNG_THREASHHOLD = 5; // seconds + const time_t HUNG_THREASHHOLD = 300; // seconds int ii; time_t now = time( NULL ); for ( ii = 0; ii < m_nThreads; ++ii ) { @@ -487,8 +485,10 @@ XWThreadPool::log_hung_threads( void ) if ( 0 != recentTime ) { time_t howLong = now - recentTime; if ( HUNG_THREASHHOLD < howLong ) { - logf( XW_LOGERROR, "thread %d stopped for %d seconds!", ii, howLong ); + logf( XW_LOGERROR, "thread %d (%p) stopped for %d seconds!", + ii, tip->thread, howLong ); tip->recentTime = 0; // only log once + assert(0); } } } diff --git a/xwords4/relay/tpool.h b/xwords4/relay/tpool.h index 0c3e1e404..9bf4d8f93 100644 --- a/xwords4/relay/tpool.h +++ b/xwords4/relay/tpool.h @@ -44,6 +44,7 @@ class XWThreadPool { typedef struct _ThreadInfo { XWThreadPool* me; + pthread_t thread; time_t recentTime; } ThreadInfo; From 6dcd7022d499198a1d88c58f3c1758d9bb9e95b5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 11 Jan 2013 20:42:57 -0800 Subject: [PATCH 3/3] don't pass .css file in; it's ignored --- xwords4/relay/xwrelay.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xwords4/relay/xwrelay.sh b/xwords4/relay/xwrelay.sh index 5a53b697d..111797100 100755 --- a/xwords4/relay/xwrelay.sh +++ b/xwords4/relay/xwrelay.sh @@ -7,7 +7,6 @@ XWRELAY=${DIR}/xwrelay PIDFILE=${DIR}/xwrelay.pid CONFFILE=${DIR}/xwrelay.conf IDFILE=${DIR}/nextid.txt -CSSFILE=${DIR}/xwrelay.css LOGFILE=/tmp/xwrelay_log_$$.txt #LOGFILE=/dev/null @@ -98,8 +97,8 @@ do_start() { exit 1 fi echo "starting..." | tee -a $LOGFILE - echo "running $XWRELAY $@ -f $CONFFILE -s $CSSFILE" | tee -a $LOGFILE - $XWRELAY $@ -f $CONFFILE -s $CSSFILE & + echo "running $XWRELAY $@ -f $CONFFILE" | tee -a $LOGFILE + $XWRELAY $@ -f $CONFFILE & NEWPID=$! echo -n $NEWPID > $PIDFILE sleep 1