[FreeNX-kNX] round-robin bug?
Chris Fanning
christopher.fanning at gmail.com
Thu Jan 31 12:37:15 UTC 2008
Hi,
I may be doing something terribly wrong but..
I have problems if I use round-robin
LOAD_BALANCE_SERVERS="10.200.61.218 10.200.61.217"
LOAD_BALANCE_ALGORITHM="round-robin"
It doesn't work and nxserver.log says:
Load-Balancing: Round-Robin failed to gain lock file in 200 tries.
Falling back to random.
So I had a look at /usr/NX/bin/nxserver
_______________________
# Enter critical section
# - Create .lock file
SERVER_LB_LOCKFILE=$(mktemp "$NX_SESS_DIR/round-robin.lock.XXXXXXXXX")
trap "rm -f $SERVER_LB_LOCKFILE" EXIT
i=0
while [ $i -lt 200 ]
do
# ln is an atomic operation
##### cannot create link because "$NX_SESS_DIR/round-robin.lock"
already exists (wasn't removed)
ln $SERVER_LB_LOCKFILE "$NX_SESS_DIR/round-robin.lock" && break
LANG=C sleep 0.01
let i=i+1
done
if [ $i -ge 200 ]
then
log 1 "Load-Balancing: Round-Robin failed to gain lock file in
200 tries. Falling back to random."
server_loadbalance_random
return
fi
trap "rm -f $SERVER_LB_LOCKFILE $NX_SESS_DIR/round-robin.lock" EXIT
# Lock held
SERVER_LB_NR=$(cat $NX_SESS_DIR/round-robin 2>/dev/null)
let SERVER_LB_NR=(SERVER_LB_NR+1) % SERVER_LB_NR_OF_HOSTS
#### if $SERVER_LB_NR == $SERVER_LB_NR_OF_HOSTS then SERVER_LB_HOST
gets set to "127.0.0.1"
#### so I reset it.
if [ $SERVER_LB_NR -ge $SERVER_LB_NR_OF_HOSTS ]
then
let SERVER_LB_NR=0
fi
echo $SERVER_LB_NR >$NX_SESS_DIR/round-robin
# Exit critical section
#### this doesn't remove $SERVER_LB_LOCKFILE, so
"$NX_SESS_DIR/round-robin.lock" doesn't get removed either.
rm -f "$SERVER_LB_LOCKFILE $NX_SESS_DIR/round-robin.lock"
#### so I remove round-robin.lock
rm -f "$NX_SESS_DIR/round-robin.lock"
#### I don't know why but $SERVER_LB_LOCKFILE doesn't get removed
#### Something to do with SERVER_LB_LOCKFILE=$(mktemp
"$NX_SESS_DIR/round-robin.lock.XXXXXXXXX") ??
rm -f $SERVER_LB_LOCKFILE ### fails
trap - EXIT
SERVER_LB_HOST=${SERVER_LB_HOSTS[$SERVER_LB_NR]}
echo $SERVER_LB_HOST
________________________
And now it works. although /usr/NX/var/db gets full of
$SERVER_LB_LOCKFILE files.
Maybe as an alternative something like this would work? I don't really know.
____________________
if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null;
then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
critical-section
rm -f "$lockfile"
trap - INT TERM EXIT
else
echo "Failed to acquire lockfile: $lockfile."
echo "Held by $(cat $lockfile)"
fi
_____________________
Cheers,
Chris.
More information about the FreeNX-kNX
mailing list