karma-runner / karma

Spectacular Test Runner for JavaScript
http://karma-runner.github.io
MIT License
11.96k stars 1.71k forks source link

karma server locks file. #1421

Open unional opened 9 years ago

unional commented 9 years ago

When karma server is running (0.12.31 and 0.12.32), the source files are locked once the file has been changed.

Once the karma server is stopped the files are unlocked.

This cause the source files cannot be changed more than once during development (e.g. phpStorm fails with "Cannot Save Files", and p4 cannot submit changes or revert the file: "cannot create a file when that file already exists") until I stop the karma server.

maksimr commented 9 years ago

@unional Thanks! What OS and phpStorm you use? It will be cool if you create test project where reproduce this problem

bd82 commented 9 years ago

Hello.

I've also encountered this lately when migrating a project to Karma. That project is proprietary so I can't share the code it. However I'll try to reproduce the issue in a test project.

OS I am running is windows7 and the IDE is IntelliJ IDEA 14.1 Karma Version: 0.12.35 (updated to latest and the issue still occurs )

unional commented 9 years ago

I kind of get around this problem by not including the spec folder which contains the karma.conf files. After I do that, the problem goes away. There should be a bug somewhere that causing this, because including the spec files should not cause source files to be locked.

By the way, using exclude: [] to exclude the spec files doesn't work. I have to write the patterns inside files: [] specifically to avoid the spec folder (e.g., not using {pattern: "**/*", included: false}).

I'm using Windows 2012 Server R2 and phpStorm 8/9. I've tested that it is not due to phpStorm at all. I encounter the same problem when I start karma form command line.

bd82 commented 9 years ago

Some observations:

Assume the following directory structure: ROOT

The issue will occur for files under 'C' but not for files under 'A'. renaming 'C' to 'AA' will 'solve' the problem. it seems it be be related to some alphabetical/hierarchical ordering of the files. possibly combined with a timing issue.

another workaround is to disable Intellij's 'safe file write' capture

Using 'safe file write' Intellij:

  1. creates a new file with the new contents.
  2. deletes the old file with the original name.
  3. renames the new file to the original name.

I am guessing it is possible that Intellij does these 3 steps very quickly and this conflicts with some background process scanning for new files (in the web server?).

Note that the workaround suggested above is is not a complete workaround as other actions in Intellij can still the issue even with the 'safe file write' checkbox disabled. for example reverting via VCS UI.

I've been unable to reproduce the issue on my personal desktop. I'll give it another try to creating a sample project reproducing the issue on my work laptop.

unional commented 9 years ago

For me I was able to reproduce the issue without phpStorm, i.e. just run karma from command line and try to checkout / update / revert files from p4v.

On Tue, Jun 2, 2015 at 9:24 AM Shahar Soel notifications@github.com wrote:

Some observations:

Assume the following directory structure: ROOT

  • Folder A
  • Folder B (many files here, in my case 90mb, >2,500 files)
  • Folder C

The issue will occur for files under 'C' but not for files under 'A'. renaming 'C' to 'AA' will 'solve' the problem. it seems it be be related to some alphabetical/hierarchical ordering of the files. possibly combined with a timing issue.

another workaround is to disable Intellij's 'safe file write' [image: capture] https://cloud.githubusercontent.com/assets/4233843/7940704/2ef6206a-095b-11e5-8daf-c8931a306753.PNG

Using 'safe file write' Intellij:

  1. creates a new file with the new contents.
  2. deletes the old file with the original name.
  3. renames the new file to the original name.

I am guessing it is possible that Intellij does these 3 steps very quickly and this conflicts with some background process scanning for new files (in the web server?).

Note that the workaround suggested above is is not a complete workaround as other actions in Intellij can still the issue even with the 'safe file write' checkbox disabled. for example reverting via VCS UI.

I've been unable to reproduce the issue on my personal desktop. I'll give it another try to creating a sample project reproducing the issue on my work laptop. I'm beginning to suspect that if it is a timing issue it may be also affected by disk encryption/anti virus software.

— Reply to this email directly or view it on GitHub https://github.com/karma-runner/karma/issues/1421#issuecomment-108005786 .

bd82 commented 9 years ago

reproducible project: http://www.filedropper.com/reproduce

steps to reproduce:

  1. unzip the project
  2. npm install
  3. npm test (this will do karma start)
  4. open WebStorm/Intellij and modify the file: src\main\webapp\test-resources\try_to_modify_me.js several times (make sure to save each time (ctrl-s on eclipse keymap))
    • I've had to place two copies of the angular.js repository in the src directory to reproduce the issue. with only one copy the problem did not occur.
    • Also tested on a Windows8 machine, There problem did not occur there.