Weird resource leak related to gulpfile or git or cmd prompt

91 Views Asked by At

I have a gulpfile in a project directory. I use gulp frequently and this file is similar to my different gulpfile's that I've used many times before.

I first became aware of this problem when I tried to merge a git commit and git threw an error that it couldn't unlink the gulpfile. I assumed that the gulpfile was in use by some other program, so I closed everything, including my command prompt, and terminated all processes that could theoretically be involved. Then I tried to merge in my git gui and got the same error.

I went into the directory using the command prompt and typed handle gulp (handle is a program by SysInternals that is designed to display information about what file handles are in use by what programs), and I see repeated instances of that gulpfile that are in use by the cmd.exe process I'm currently using and the handle.exe command. One thing I eventually figured out is that every time I type handle gulp, a new handle is created attached to the command prompt and attached to any other process that are started from the command prompt in that directory.

Here is an example screenshot:

Leak screenshot


I opened up mspaint to get the above screenshot, and then searched in process explorer for gulp and this is what I see:

Process explorer leak screenshot

I could chalk all this up to being something weird with file handles, but the fact that git is unable to unlink it indicates something weirder is going on. Keep in mind, at no point during any of this was the gulpfile being executed.

This is what I've tried, more or less, to solve this:

  1. A variety of git commands to clean up the repo - git fsck, cleaned the dangling blobs. Also pruning and repacking and garbage collecting.
  2. handle filename where filename is any other file in that directory. No leak. The output shows No matching handles every time with everything except for the gulpfile.
  3. Searched for alternate data streams, hidden files, broken links / reparse points, bad characters in filenames .. nothing.
  4. Searched the actual gulpfile for bad characters. Nothing.
  5. chkdsk /f. The log said it cleaned up some indexes, but it didn't fix the problem.
  6. Closing each individual handle. I tried doing this in process explorer as wells as by using handle command line switches. In both cases, I can close all the handles, but then they begin spawning again the next time I go into the directory with the command prompt.
  7. Searched through gulp.js issues on github to try and find anything similar. I'd file an issue, but I tend to doubt gulp is the culprit - even though it sure seems to be involved somehow.

I think that might be everything. Any ideas?

UPDATE: Just checked. This process is repeatable with every single gulpfile on my system - and as far as I can tell, no other files. This is too weird.

Other Update: I did eventually solve the git issue, but I'm still not sure what caused it, and the way I fixed it involved extra work and changing the master branch.

FINAL UPDATE: This has not stopped driving me crazy. Finally today I figured it out, and I feel like an idiot.

I use ConEmu and Clink for my terminal. Shortly before this started happening (but long enough so that I didn't make the connection), I fiddled around with clink and lua to create some features in my terminal. I created completions for openapi-generator and some other command line tools that I used, and it was pretty useful. I also took advantage of the feature that allows you to decorate the command prompt based on a file in the current directory. I added a cool little gulp icon on every directory that had a gulpfile.js file in it. And thus .....

The io kept creating handles every time I went into the directory, and as such I lost many hours of my life trying to figure this out.

I'm sure there's a moral here, but I'll be dammed if I know what it is.

0

There are 0 best solutions below