Saved from an episode of bear shaving

As part of our continuous integration build we have a step in the build which tears down a Windows service, uninstalls it and then reinstalls it later on from the latest files checked into the repository.

One problem we’ve been having recently is that despite the fact it should already have been uninstalled a lock has been kept on the log4net dll in our build directory, a directory that we tear down as one of the next steps.

It was a bit of a sporadic failure and whenever we went on the build machine and checked for file handles with Process Explorer the log4net dll never showed up on the list.

I wrongly assumed that it couldn’t be getting locked by the Windows service because the Windows service would already be gone by that stage.

We therefore started on a bear shaving expedition which involved trying to make use of Unlocker and File Assassin to release the file handle so that we’d be able to delete the directory.

We weren’t able to get either of those tools to do the job from the command line and luckily at this stage another colleague had the idea to check whether or not the Windows service was actually immediately removed in Task Manager when we tore it down.

After realising that it wasn’t we were able to address this problem and put a step in the build to look for that process and kill it as part of the build.

I guess the real solution to this problem would be for the uninstall to block until it was properly uninstalled but this seems to be the closest we can get to addressing the cause rather than the effect.

This entry was posted in software-development. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

One Response to Saved from an episode of bear shaving

  1. Ian says:

    We do the exact same thing at my work and use nant to stop the service first before uninstalling/reinstalling. The trick is that when you send a STOP command to a service you should then keep polling its status – it will remain in STOP_PENDING for a while before finally becoming STOPPED. Once stopped your files will be unlocked.

    The command line tool “SC” is the one for this job with its “query” and “stop”/”start” params.

Leave a Reply