diff --git a/idl/mdsconnect.pro b/idl/mdsconnect.pro index 77e5fea488..1b0398e13a 100644 --- a/idl/mdsconnect.pro +++ b/idl/mdsconnect.pro @@ -6,7 +6,8 @@ endcase end function sockmin - if !version.os eq 'linux' then return, 0 else return, 11-(!version.os eq 'MacOS') + ; Connection IDs start at 1 (see Issue #2625 for details). + if !version.os eq 'linux' then return, 1 else return, 11-(!version.os eq 'MacOS') end function mds$socket,quiet=quiet,status=status,socket=socket diff --git a/mdstcpip/mdsipshr/Connections.c b/mdstcpip/mdsipshr/Connections.c index 297614d235..90fe125436 100644 --- a/mdstcpip/mdsipshr/Connections.c +++ b/mdstcpip/mdsipshr/Connections.c @@ -465,13 +465,17 @@ static inline int authorize_client(Connection *c, char *username) int AddConnection(Connection *c) { MDSIPTHREADSTATIC_INIT; + + // Connection IDs are issued in sequence. + // Issue #2625 requires connection IDs starting at 1 to avoid IDL issues. + // Use of _FindConnection() is an integrity check of the data structures. static int id = INVALID_CONNECTION_ID; static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&lock); do { - id++; // find next free id - } while (id == INVALID_CONNECTION_ID && _FindConnection(id, NULL, MDSIPTHREADSTATIC_VAR)); + id++; + } while ((id == INVALID_CONNECTION_ID) || (id == 0) || _FindConnection(id, NULL, MDSIPTHREADSTATIC_VAR)); c->id = id; pthread_mutex_unlock(&lock); c->state |= CON_INLIST;