bradlepc has asked for the wisdom of the Perl Monks concerning the following question:

I'm seeing a lot of strange hangs when my Perl scripts are run by a Windows service. The service should be ok (3rd party, works for other executables. The hangs seem to take two forms: Service runs Perl script which runs another perl script. Second script hangs as it exits Service runs Perl script which runs another perl script. Perl hangs doing file I/O (using open()). I'm using ActiveState (latest version)
  • Comment on Freakish Perl hangs when run by Windows Service

Replies are listed 'Best First'.
Re: Freakish Perl hangs when run by Windows Service
by Aristotle (Chancellor) on Jun 17, 2002 at 22:53 UTC
    I have no idea what I'm talking about, but I seem to have a vague recollection of services running under (an) account(s) with certain restrictions. Maybe that poses a problem? Is the script in the first scenario trying to pipe data to the child script, or reading output from it back in (that would obviously lead us back to the second scenario)? Can you pinpoint where your scripts hang during I/O? (On open, as your second point seems to imply, or don't you know more precisely?)

    Makeshifts last the longest.

      There seem to be several failure modes. Based on print statements, one situation occurs after the child script has completed. Somehow the child process is hanging on exit. There's no explicit piping going on, although stdout and stderr are being inherited from the calling script.
Re: Freakish Perl hangs when run by Windows Service
by cmilfo (Hermit) on Jun 18, 2002 at 03:27 UTC
    Screamer has a couple of good points on permissions of services. I've run into several instances where I did not have permission to read/write to a folder. I was not catching/logging the exception correctly. If you use a tool like PerlApp/PerlSvc, they will do some logging to the Windows Event Log for you. If you are rolling your own logging, might I suggest the CPAN (Win32::EventLog).

    Even though your 3rd-party-service-program-runner-thingy works for other executables, you may be running into trouble running a script through Perl. You might try moving your parent script to be a service itself and starting/stopping it through the services API, which is quite dandy. If you go this route, there are two modules that make the job quite easy, Win32::Daemon and Win32::Process. I've had a lot of success using these two modules together -- in conjunction with the afore mentioned logging module.

    If you would like more specific help rather than random, "hey try this" advice, post some code so we can dig through it!

    Good Luck!
    Casey
      These are some good thoughts. I think I need to provide some more details though. The perl script doesn't always hang. It often does, but not always. Also, there are several different scripts that all hang from time to time. Usually the first few times after a reboot work; eventually I get the hang. Making the Perl its own service is not an option because I need other features of the service. An easy way to think of this (and I've demonstrated the hang this way) is RSHing the script on a host.