Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The process cannot access the file because it is being used by another process. #28

Closed
roberto-rodriguez opened this issue Sep 18, 2019 · 24 comments · Fixed by #51
Closed
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@roberto-rodriguez
Copy link

These are the logs:

Generating certificates...
[0] Certificates path: C:\Users\roberto.rodriguez\AppData\Roaming\https-localhost.
[0] Downloading the mkcert executable...
[0] Running mkcert to generate certificates...
[0] (node:13992) UnhandledPromiseRejectionWarning: Error: Command failed: C:\Users\roberto.rodrigu4.exe -install -cert-file C:\Users\roberto.rodriguez\AppData\Roaming\https-localhost\localhost.crtocalhost\localhost.key localhost
[0] The process cannot access the file because it is being used by another process.
[0]
[0] at ChildProcess.exithandler (child_process.js:294:12)
[0] at ChildProcess.emit (events.js:182:13)
[0] at maybeClose (internal/child_process.js:962:16)

@daquinoaldo
Copy link
Owner

Hi, which command do you use to run the script?

@camous
Copy link

camous commented Aug 9, 2020

I face the same situation when for the first attempt of calling ./serve (windows/powershell/administrator).

Running in a separate shell command
mkcert-v1.4.1-windows-amd64.exe" -install -cert-file "C:\Users\username\AppData\Roaming\https-localhost\localhost.crt" -key-file "C:\Users\username\AppData\Roaming\https-localhost\localhost.key" localhost

generated the certificate files and then serve was working just fine.

full error stack.

Generating certificates...
Certificates path: C:\Users\username\AppData\Roaming\https-localhost. Never modify nor share this files.
Downloading the mkcert executable...
http to https redirection active.
Running mkcert to generate certificates...
(node:5160) UnhandledPromiseRejectionWarning: Error: Command failed: "C:\Users\username\AppData\Roaming\https-localhost\mkcert-v1.4.1-windows-amd64.exe" -install -cert-file "C:\Users\username\AppData\Roaming\https-localhost\localhost.crt" -key-file "C:\Users\username\AppData\Roaming\https-localhost\localhost.key" localhost
The process cannot access the file because it is being used by another process.

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:962:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
(node:5160) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5160) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
{ [Error: ENOENT: no such file or directory, open 'C:\"C:\Users\username\AppData\Roaming\https-localhost\mkcert.log"']
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path:
   'C:\\"C:\\Users\\username\\AppData\\Roaming\\https-localhost\\mkcert.log"' }
{ [Error: ENOENT: no such file or directory, open 'C:\"C:\Users\username\AppData\Roaming\https-localhost\mkcert.err"']
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path:
   'C:\\"C:\\Users\\username\\AppData\\Roaming\\https-localhost\\mkcert.err"' }

@daquinoaldo daquinoaldo reopened this Aug 11, 2020
@daquinoaldo
Copy link
Owner

Hi @camous,
thank you for the additional information!
After launching an error, is the program able to serve pages on a secure connection? Or is it impossible without running mkcert manually?

@camous
Copy link

camous commented Aug 11, 2020

serve wasn't able to works with the error (I tested) beside the process was hanging.

I have the feeling the mkcert crashed/hang for some reasons (I was in administrator) making the promise fails.

when running mkcert manually (from command line directly), I think I remember I had a dialog box asking me to install the certificate in my local store (sorry I don't have the screen). maybe this dialog box on my windows version/laptop from works made the promise fails ?

@daquinoaldo
Copy link
Owner

Okay, thanks for the further investigation!

I suspect the error is within this promise, but I'm running out of time in these days.
If you want to try a fix on your own, you'll have all my support and thankfulness (and you'll be mentioned as contributor). Otherwise I'll try to fix it as soon as I can.

In any case, thank you for your time and for the precise information you already provided!

@camous
Copy link

camous commented Aug 13, 2020

little bit short on time, however, will quickly check if I can remove the installed certificate in order to re-produce the issue. that would be a first step :)

@robokozo
Copy link

I'm seeing the same thing.

Generating certificates...
Certificates path: C:\Users\username\AppData\Roaming\https-localhost. Never modify nor share this files.
Downloading the mkcert executable...
Running mkcert to generate certificates...
(node:32520) UnhandledPromiseRejectionWarning: Error: Command failed: "C:\Users\username\AppData\Roaming\https-localhost\mkcert-v1.4.1-windows-amd64.exe" -install -cert-file "C:\Users\username\AppData\Roaming\https-localhost\localhost.crt" -key-file "C:\Users\username\AppData\Roaming\https-localhost\localhost.key" localhost
The process cannot access the file because it is being used by another process.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
(node:32520) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:32520) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

daquinoaldo added a commit that referenced this issue Aug 31, 2020
This may fix issue #28 but requires more tests on Windows
@daquinoaldo
Copy link
Owner

Hi guys,
thank you for reporting.

I've opened a branch for investigating the problem. I found path formatting error on macOS. I fixed on darwin architectures (see the above commit), but I need to test it on Windows. Anyway, probably the cause it will be the same.
I'm preparing a Windows test machine; I hope to work on a fix in the next days. Then I'll need your feedback.
Stay connected!

@daquinoaldo
Copy link
Owner

daquinoaldo commented Sep 2, 2020

@robokozo @camous
After some tests, the bug seems to be fixed. Could you please try again?

# uninstall any version of https-localhost (if any)
npm i -g https-localhost

# install the fixed version directly from the GitHub branch
npm install -g git://github.com/daquinoaldo/https-localhost.git#fix-issue-28

It should work.
If not, or if you have just a bit of time to make further investigations, please run the tests.

# uninstall any version of https-localhost (if any)
npm i -g https-localhost

# clone the fix-issue-28 branch of this repository
git clone -b fix-issue-28 https://github.com/daquinoaldo/https-localhost
# if you don't have git just download [this zip](https://github.com/daquinoaldo/https-localhost/archive/fix-issue-28.zip) and unzip it

# move into the folder
# should work also on Windows, but anyway, just open a terminal inside the directory you have cloned/downloaded
cd https-localhost

# install dependencies
npm i

# run tests
npm t

# if tests fail please paste here the output and run them again, second time should work
npm t

Troubleshooting: try to delete those two folders (it is safe, they are created by my script). Then try to install it or to run tests again.

C:\Users\aldod\AppData\Roaming\https-localhost
C:\Users\aldod\AppData\Local\mkcert

Thanks for your time, I really appreciate it.

EDIT: just a couple of notes.

  1. Please, remember that the latest npm version, that you install with npm i -g https-localhost, is not yet fixed. I'll publish this updated version after your tests.
  2. At the first run and during tests you will likely be prompted for permission to install the generated certificate, so that it is recognized by the browser. You need to click yes and allow it, otherwise the installation or the tests will fail.

@daquinoaldo daquinoaldo added the bug Something isn't working label Sep 2, 2020
@robokozo
Copy link

robokozo commented Sep 2, 2020

I ran the tests and this is the result:


Testing certs
    √ can be uninstalled
    √ uninstall is idempotent (doesn't fail if called twice)
Generating certificates...
Certificates path: C:\Users\user\AppData\Roaming\https-localhost. Never modify nor share this files.
Downloading the mkcert executable...
Running mkcert to generate certificates...
(node:19640) UnhandledPromiseRejectionWarning: Error: Command failed: "C:\Users\user\AppData\Roaming\https-localh               ost\mkcert-v1.4.1-windows-amd64.exe" -install -cert-file "C:\Users\user\AppData\Roaming\https-localhost\localhost               .crt" -key-file "C:\Users\user\AppData\Roaming\https-localhost\localhost.key" localhost
The process cannot access the file because it is being used by another process.

    at ChildProcess.exithandler (child_process.js:295:12)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
(node:19640) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwin               g inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().                (rejection id: 1)
(node:19640) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise reje               ctions that are not handled will terminate the Node.js process with a non-zero exit code.

@daquinoaldo
Copy link
Owner

Thanks @robokozo!
Did this occur also the second time you ran the tests?

@robokozo
Copy link

robokozo commented Sep 2, 2020

Yes, I'm afraid so

@daquinoaldo
Copy link
Owner

I've ran other tests and even after many attempts I still unable to reproduce the issue. I tried to investigate the causes, but I can't find any parallelization errors: I await all the needed promises and call sync APIs on fs, the code is almost sequential.
I'm sorry for this. I'll be happy to help you if you can further investigate the problem and catch the bug origin.
Thank you for your comprehension.

@daquinoaldo daquinoaldo added hacktoberfest help wanted Extra attention is needed labels Sep 16, 2020
@Xeonzinc
Copy link

Xeonzinc commented Oct 5, 2020

Hi, probably not much help but I'm getting the same error on windows with your 'fix-issue-28' version. And as others have mentioned running the exact same command mentioned in the error manually works correctly strangely.

@NoelJacob
Copy link

NoelJacob commented Oct 6, 2020

Hey, probably you know it but, I npm installed the fix-issue-28 version and everything works perfectly. I also git cloned fix-issue-28 and ran the tests; all of which pass.

I'm running Windows Insider: 20226.1000. Node.js: v14.12.0

For me, the version on npm produces the following error on first run.

C:\Users\Janice# serve
Serving static path: C:\Users\Janice
Generating certificates...
Certificates path: C:\Users\Janice\AppData\Roaming\https-localhost. Never modify nor share this files.
Downloading the mkcert executable...
http to https redirection active.
Running mkcert to generate certificates...
Certificates generated, installed and trusted. Ready to go!
Server running on port 443.
[Error: ENOENT: no such file or directory, open 'C:\Users\Janice\"C:\Users\Janice\AppData\Roaming\https-localhost\mkcert.log"'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\Users\\Janice\\"C:\\Users\\Janice\\AppData\\Roaming\\https-localhost\\mkcert.log"'
}
[Error: ENOENT: no such file or directory, open 'C:\Users\Janice\"C:\Users\Janice\AppData\Roaming\https-localhost\mkcert.err"'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\Users\\Janice\\"C:\\Users\\Janice\\AppData\\Roaming\\https-localhost\\mkcert.err"'
}

After installing the certificate in C:\Users\Janice\AppData\Roaming\https-localhost, running serve with npm version works perfectly.

@daquinoaldo
Copy link
Owner

Hi @NoelJacob,
thank you for the feedback.

The error at first run happens only with the public version, the latest release on npmjs.org, and not with the fix-issue-28, is that right?

If so, publishing the fix branch on npm should fix at least the missing file problem (i.e. the wrong path construction bug).

@NoelJacob
Copy link

yes it should fix the problem

@yakunins
Copy link

yakunins commented Oct 6, 2020

Have the same problem. So, I cloned fix-issue-28, run npm install, run npm run test and got exactly the same error:

Downloading the mkcert executable...
Running mkcert to generate certificates...
(node:15488) UnhandledPromiseRejectionWarning: Error: Command failed: ...
The process cannot access the file because it is being used by another process.
  • Windows 10
  • tested on both node 14.12.0 and 12.18.4
  • directory ...\AppData\Roaming\https-localhost has no .key or .crt files
  • I have just noticed, npm run test creates three node's processes, maybe they are blocking each other?

image

image

@daquinoaldo
Copy link
Owner

daquinoaldo commented Oct 9, 2020

Hi @yakunins (and @Xeonzinc, @robokozo, @camous),

could you please try again on fix-issue-38?

  1. Delete these two directories:
C:\Users\aldod\AppData\Roaming\https-localhost
C:\Users\aldod\AppData\Local\mkcert
  1. Uninstall https-localhost and install the fix branch
# uninstall any version of https-localhost (if any)
npm i -g https-localhost

# install the fixed version directly from the GitHub branch
npm install -g git://github.com/daquinoaldo/https-localhost.git#fix-issue-28

I'm still not be able to reproduce the bug. I remove the log files (1574929). That should fix the ENOENT. Also, I added a 3 seconds sleep on Windows (5dda801), even if it should be a sync call.
@yakunins tests should not be run in parallel and all async functions are awaited using the done() callback. Anyway, at runtime there is no parallelism at all.

Any further suggestion, feedback or other contribution is welcome.
Thank you for your cooperation.

@camous
Copy link

camous commented Oct 9, 2020

hey @daquinoaldo , sorry for not answering before :/

however, followed your instruction and it works for me. however is it exactly from an exact vanilla computer ? I will try on my other computer just after.

  1. deleted 2 folders

  2. uninstall
    image

  3. install specific branch
    image

  4. serve
    image

  5. success
    image

@camous
Copy link

camous commented Oct 9, 2020

on a clean computer, running serve for the first time with admistrator permission with branch git://github.com/daquinoaldo/https-localhost.git#fix-issue-28 it worked for me.

image

image

daquinoaldo added a commit that referenced this issue Oct 10, 2020
Fix issue #28: the file is being used by another process on Windows
@daquinoaldo
Copy link
Owner

Thank you, guys!
If someone still experiment this problem, feel free to comment this issue and we will discuss it again.

@yakunins
Copy link

@daquinoaldo Thank you, tests are passed.

image

@daquinoaldo
Copy link
Owner

By the way, the fix has been released in v4.6.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants