🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11089

Re: Problem with Service Hanging

#11089
From: Jt
Date: Thu, 26 Feb 2004 17:36
89 lines
4188 bytes
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:403d3651$1@newsgroups.borland.com...
>
> "Bob Gonder" <notbg@notmindspring.invalid> wrote in message
> news:25cq305gvts4b23ajlk1j18te0ctcsposn@4ax.com...
>
> > I've never thought about CreateFile hanging. Always
> > expect it to return one way or another.
>
> Agreed.  I've never seen it happen myself either.  But from Jt's original
> message, that is the only way TFileStream's constructor can freeze, since
> all it does is call either FileOpen() or FileCreate() based on the Mode
> parameter, which in turn simply call CreateFile() directly with various
> parameters.
>
> > Spec#1) Might the file be a "temporary" file that the os
> > deletes as soon as it is closed? Trapping the Open mid-stream?
>
> I would expect CreateFile() to fail on that.
>
> > Spec#2) Might there be a "race" condition in the os where the
> > file "starts" to be created, his services gets notified, and he tries
> > to open the file before it is fully created?
>
> Hmm, interesting.  Considering that Jt has not yet answered my question
> regarding *when* he is calling his OpenFile() method, that might be a
> possibility.
>
>
> Gambit
>
>



void __fastcall TScanThread::Execute()
{
const TCHAR szDirectory[]       = "D:\\Apps\\CDNT\\Verizon";    // directory
const DWORD ExitPollInterval    = 5 * 60 * 1000; // milliseconds

HANDLE hChange = FindFirstChangeNotification(
    szDirectory,                  // directory to monitor
    FALSE,                        // don't monitor sub-directories
    FILE_NOTIFY_CHANGE_FILE_NAME  // notifiy on file rename, create or
delete
    );

if( FindNextChangeNotification( hChange ) )
    while(!Terminated)
        {
        DWORD WaitResult = WaitForSingleObject(    // enter efficient wait
state
            hChange,
            ExitPollInterval
            );

        if( WaitResult == WAIT_OBJECT_0 )    // a file has changed
            {
            ptr = fopen("d:\\Apps\\CDNT\\Verizon\\Processed\\log.txt", "a");
            // Process new file
            fprintf(ptr, "Scanning for file %s\n", DateTimeToStr(Now()));

            bool goodScan = Scan();

 inside the scan function  i call a function to check oracle to make sure
the file has not all ready been loaded. If it has no then I call the
OpenFile() function.

            fclose(ptr);
            }
        else if( WaitResult == WAIT_TIMEOUT )    // timeout has occured
without a change notification
            continue;                            // check StopMonitoring
flag, then continue
        else
            break;                               // something unexpected
happened, stop monitoring

        if( !FindNextChangeNotification( hChange ) )
            break;
        }

FindCloseChangeNotification( hChange );
}

I have added more granular logging as suggested. I am not able to reproduce
this error when testing it. I have to just let in run in production for a
day or two and the problem will reoccur.
Technical Details
Message-ID: <403e2ea7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <403d08c8$1@newsgroups.borland.com> <403d27c0$1@newsgroups.borland.com> <25cq305gvts4b23ajlk1j18te0ctcsposn@4ax.com> <403d3651$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,f5b18ffe280796bd
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-26 09:40:25 PST
From: "Jt" <jtoland@bullseyetelecom.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <403d08c8$1@newsgroups.borland.com> <403d27c0$1@newsgroups.borland.com> <25cq305gvts4b23ajlk1j18te0ctcsposn@4ax.com> <403d3651$1@newsgroups.borland.com>
Subject: Re: Problem with Service Hanging
Date: Thu, 26 Feb 2004 12:36:27 -0500
Lines: 91
Organization: Bullseye
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 207.148.192.94
Message-ID: <403e2ea7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1077816999 207.148.192.94 (26 Feb 2004 09:36:39 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail