host name is returned empty for a brief window in time after the channel connects

Bug #541342 reported by Jeff Hill on 2008-03-12
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Wishlist
Jeff Hill

Bug Description

From Ernest:

> I thought cainfo would return the host:
>
> [iocegr@lcls-builder ~]$ cainfo PCAV:IN20:365:TEMP2
> PCAV:IN20:365:TEMP2
> State: connected
> Host:
> Access: read, write
> Data type: DBR_DOUBLE (native: DBF_DOUBLE)
> Element count: 1
>
>
> probe returns the host of the PV just fine.
>
> I tried this with EPICS R3.14.8.2 and also EPICS R3.14.9 as well.
>

Original Mantis Bug: mantis-312
    http://www.aps.anl.gov/epics/mantis/view_bug_page.php?f_id=312

Jeff Hill (johill-lanl) wrote :

I reproduced this here (on windows using excas as the server). I had some mixed results. See below. I'm not certain what is going on, but here is a possible explanation. In R3.14 all DNS queries are handled by an independent thread, and their results are returned asynchronously via callbacks. This makes CA immune to lockups when DNS goes down. I suspect that the host name is set to empty until this query comes back. So if you ask right away after the channel connects you get an empty host name. This could possibly be improved by copying the dotted IP address into the host name string - to be used until the dns name comes back.

Jeff Hill (johill-lanl) wrote :

I applied this patch.

cvs diff -wb -- hostNameCache.cpp (in directory C:\hill\R3.14.dll_hell_fix\epics\base\src\ca\)
Index: hostNameCache.cpp
===================================================================
RCS file: /net/phoebus/epicsmgr/cvsroot/epics/base/src/ca/hostNameCache.cpp,v
retrieving revision 1.17.2.4
diff -u -b -w -b -r1.17.2.4 hostNameCache.cpp
--- hostNameCache.cpp 19 Oct 2004 20:24:35 -0000 1.17.2.4
+++ hostNameCache.cpp 22 Sep 2008 20:15:43 -0000
@@ -33,6 +33,9 @@
     const osiSockAddr & addr, ipAddrToAsciiEngine & engine ) :
     dnsTransaction ( engine.createTransaction() ), nameLength ( 0 )
 {
+ sockAddrToDottedIP ( &addr.sa, hostNameBuf, sizeof ( hostNameBuf ) );
+ hostNameBuf[ sizeof ( hostNameBuf ) - 1 ] = '\0';
+ nameLength = strlen ( hostNameBuf );
     this->dnsTransaction.ipAddrToAscii ( addr, *this );
 }

@@ -49,12 +52,15 @@
 void hostNameCache::transactionComplete ( const char * pHostNameIn )
 {
     epicsGuard < epicsMutex > guard ( this->mutex );
- if ( this->nameLength == 0u ) {
- strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) );
+ // a few legacy clients have a direct pointer to this buffer so we
+ // set the entrire string to nill terminators before we start copying
+ // in the name (this reduces the chance that another thread will see
+ // garbage characters).
+ strncpy ( this->hostNameBuf, "", sizeof ( this->hostNameBuf ) );
+ strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) - 1 );
         this->hostNameBuf[ sizeof ( this->hostNameBuf ) - 1 ] = '\0';
         this->nameLength = strlen ( this->hostNameBuf );
     }
-}

 unsigned hostNameCache::getName (
     char * pBuf, unsigned bufSize ) const

Jeff Hill (johill-lanl) wrote :

fixed in R3.14.10

Andrew Johnson (anj) wrote :

R3.14.10 released.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers