Page 1 of 1

Lock errro

Posted: Wed May 11, 2011 7:01 am
by omni
Roger,

We have a stand-alone exe that runs on one of users server (win2003). No client server.

This process downloads data (mobile locations, messages,etc) from a web site 24/7. The files that are updated are fairly large, 50,000-500,00 records. Never a problem on these files. About 30-50 times daily there are special routines to update other files which are very small. One is driving us crazy. 130 records, its driver hours used the prior day. When the messages come in, we open the file, find the driver record, lock it, update, unlock it and close it. There is a lock error almost every day on one of these, even though the lock routine is successful. Just says lock is required for this operation and the exe locks up. The user is getting very upset at this as the exe stops running until they cancel and restart it.
This is our record locking routine..used now for 8 years. There is no alert message, so the lock had to be successful.

FUNCTION OISRCLCK
LOCAL XLOCK
XLOCK=.F.
DO WHILE .NOT. ( XLOCK := RLOCK() )
n := DC_GuiAlert(,"Unable to lock record #" + LTRIM(STR(RECNO())) + IF(EOF()," (EOF) ","") + " of " + ;
IF( !EMPTY(ALIAS()),UPPER(ALIAS())," Work Area #" + LTRIM(STR(SELECT())) ) + ". ;" + ;
"Procedure " + UPPER(PROCNAME(0)) + " -- line " + LTRIM(STR(PROCLINE(0),5)) + ";" + ;
"Procedure " + UPPER(PROCNAME(1)) + " -- line " + LTRIM(STR(PROCLINE(1),5)) + ";" + ;
" " ,{ "Retry", "Quit" } ,14,"Error Warning",,,{"9.Arial Bold","9.Arial Bold" })
if n=2
return .f.
else
loop
endif

ENDDO
RETURN .t.


Any recommendations?

Thanks

Fred Henck
omni

Re: Lock errro

Posted: Wed May 11, 2011 7:18 am
by Tom
Hi, Fred.

This condition is never true:

DO WHILE .NOT. ( XLOCK := RLOCK() )

xLock := RLock() means xLock becomes RLock(). This happens anyway, even if RLock returns false. This should be correct:

DO WHILE .NOT. ( XLOCK = RLOCK() )

Your app worked so far by mistake: This (a failing lock) simply never happend until now. ;)

Re: Lock errro

Posted: Wed May 11, 2011 9:33 am
by skiman
Tom wrote: This condition is never true:
DO WHILE .NOT. ( XLOCK := RLOCK() )
If the rlock is succesfull it return .T., this way xlock also becomes equal to .T..

Just wondering why the xlock var is used.
'Do while !rlock()' would be a shorter notice.

With this locking system, there is a dc_guialert each time there is a lock error. Sometimes a second try after a sleep(10) could be succesfull, and everything would work without any problem.

Code: Select all

nCounter := 0
do while !rlock()
    if nCounter > 5    // after 5 tries give the alert
        n := dc_guialert....
        if n = ....
             exit
        endif
    else                // wait and retry
         nCounter ++
         sleep(10)
   endif
enddo

Re: Lock errro

Posted: Wed May 11, 2011 10:07 am
by Tom
@Chris: Damned, you're right! :shock:

Re: Lock errro

Posted: Thu May 12, 2011 4:12 am
by skiman
Tom,

There were two options: :think:
1. Someone else had used your account.
2. You had on Tuesday evening a hell of a party.

Because I'm convinced you are using this type of notation yourself in your application.

Re: Lock errro

Posted: Thu May 12, 2011 6:07 am
by rdonnay
Good eye, Tom.

I would have assumed that there was nothing wrong with the lock routine if he had been using it for years.
My first guess was that the record was getting unlocked somewhere in the code.