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

Error: Couldn't initialize the scanner: An unknown error occurred #198

Closed
barchard opened this issue Jul 20, 2017 · 24 comments
Closed

Error: Couldn't initialize the scanner: An unknown error occurred #198

barchard opened this issue Jul 20, 2017 · 24 comments

Comments

@barchard
Copy link

Hi, I have started receiving this error on Win10 (Creators Update) in Node + Electron. I am getting this error when calling .list() method in order to list devices. Strangely, this was previously working. Obviously, the error is vague so I'm not sure how to proceed. Any advice is appreciated. Thanks

@barchard
Copy link
Author

I should add, reverting to v5.0.22 fixes the issue. I will find out which version this first appears in.

@barchard
Copy link
Author

barchard commented Jul 20, 2017

NPM wouldn't allow me to install v5.0.23 or v5.0.24. It said the only versions available are v5.0.27, v5.0.26, v5.0.25, and v5.0.22. The error first appears in v5.0.25.

@rswamy
Copy link

rswamy commented Jul 20, 2017

I am setting up a new instance of my nodejs app (today) and was receiving some strange errors with the drivelist module when trying to run it. Googling led me to this issue somehow. My app fails with v5.0.27 so I reverted to v5.0.25 which I knew worked from a previous instance. Can't contribute more than this anecdote, I will need to look at what changed between these versions...

@jviotti
Copy link
Contributor

jviotti commented Jul 24, 2017

Hi @barchard @rswamy ,

NPM wouldn't allow me to install v5.0.23 or v5.0.24. It said the only versions available are v5.0.27, v5.0.26, v5.0.25, and v5.0.22. The error first appears in v5.0.25.

Sorry about that. We're adopting an company wide technology to handle automated versioning and deployment, and things didn't go very smoothly on certain versions, which have not been published to npm.


The new drivelist version contains a very large change, where we re-wrote the Windows drive scanning routines in C++, to workaround a bug coming from WMI itself, where the reported drive sizes were not accurate for some drives.

Can you guys try to re-run drivelist with the DRIVELIST_DEBUG variable set? For example:

git clone https://github.com/resin-io-modules/drivelist
cd drivelist
npm install
set DRIVELIST_DEBUG=1
node example

That should provide debugging information so we can pin-point the issue.

@barchard
Copy link
Author

When I do this, all I see in the command prompt is:

[drivelist] Initializing scanner
[drivelist] Initializing COM
[drivelist] Initializing COM security levels

Nothing else is printed.

@jviotti
Copy link
Contributor

jviotti commented Jul 24, 2017

Thanks a lot @barchard. Can you try the debug-com branch? I added even more debugging information for that particular part of the code.

@barchard
Copy link
Author

i tried building the branch then re-building it for electron. re-building the module for electron, however, fails. do you have instructions for getting it built and installed? thanks

@jviotti
Copy link
Contributor

jviotti commented Jul 24, 2017

What error message do you get? I'm on Windows 10 with Node.js 6.1.0 and it works fine here.

Try the following:

git clone https://github.com/resin-io-modules/drivelist
cd drivelist
git checkout debug-com
npm install
set DRIVELIST_DEBUG=1
node example

@rswamy
Copy link

rswamy commented Jul 25, 2017

My (probably unrelated) issue was fixed when I used nodejs 6.4.0 because apparently between v5.0.25 and v5.0.27 you used arrow notations and they aren't supported in 5.12.0 (what I was using before). Oops!

@TanninOne
Copy link

I seem to get the same error

@jviotti following your instructions I get this output:

[drivelist] Initializing scanner
[drivelist] Initializing COM
[drivelist] Initializing COM security levels
[drivelist] Creating connection instance
[drivelist] Connecting to server
[drivelist] Setting proxy security levels
Interpreting error: 0x0
[drivelist] Getting list of drives from WMI
[drivelist] Getting id
[drivelist] Processing \.\PHYSICALDRIVE0
[drivelist] Getting caption
[drivelist] Getting size
[drivelist] Opening handle on \.\PHYSICALDRIVE0
[drivelist] Getting drive geometry
[drivelist] Getting media type
[drivelist] Getting system volume drive letter
[drivelist] Getting available volumes
[drivelist] Getting volume type
[drivelist] Checking if volume has filesystem
[drivelist] Getting device number
[drivelist] Checking if disk is writable
[drivelist] Getting volume type
[drivelist] Ignoring, drive type not removable nor local
[drivelist] Getting volume type
[drivelist] Checking if volume has filesystem
[drivelist] Getting device number
Interpreting error: 0x80004005
Error: Couldn't scan the drives: An unknown error occurred
at Error (native)

@TanninOne
Copy link

Ok, investigated a bit further, it appears to be tripping over a mounted virtual device. I have a "boxcryptor classic" drive mounted on Z:. If I unmount that, the example runs fine.

@DuskDweller
Copy link

I can confirm what TanninOne reported.

@barchard
Copy link
Author

barchard commented Jul 28, 2017

Running the latest debug branch with the instructions provided worked for me. Thanks.

@jviotti
Copy link
Contributor

jviotti commented Jul 30, 2017

Awesome, thanks a lot for the help here. I'll send a PR fixing the virtual device issue and release a new version very soon!

jviotti added a commit that referenced this issue Jul 30, 2017
Drivelist currently crashes if there is a virtual drive mounted. The
best solution I could find is to check that the resulting error from
IOCTL_STORAGE_GET_DEVICE_NUMBER is "Invalid function."

Change-Type: patch
Changelog-Entry: Fix "Couldn't scan the drives: An unknown error occurred" where there is a mounted virtual drive.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Contributor

jviotti commented Jul 30, 2017

I fixed the virtual drive case in #200. @barchard the original problem you reported seems to be another one, which fails when COM is being initialized. Could it be that something changes in your machine, accidentally fixing the error by the time you tested the debug branch?

@lurch
Copy link
Contributor

lurch commented Jul 31, 2017

It seems as though all the various reports of this bug are from people running Windows 10. Do we know if this is because the bug (or bugs) are specific to Windows 10, or is it just because most people happen to be running Windows 10 now?

@barchard
Copy link
Author

barchard commented Jul 31, 2017 via email

jviotti added a commit that referenced this issue Jul 31, 2017
Drivelist currently crashes if there is a virtual drive mounted. The
best solution I could find is to check that the resulting error from
IOCTL_STORAGE_GET_DEVICE_NUMBER is "Invalid function."

Change-Type: patch
Changelog-Entry: Fix "Couldn't scan the drives: An unknown error occurred" where there is a mounted virtual drive.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@lurch
Copy link
Contributor

lurch commented Jul 31, 2017

Maybe rebooting fixed it.

Wouldn't be the first time that fixed a random Windows error... 🤣

jviotti added a commit that referenced this issue Jul 31, 2017
We use global functions to initialize COM. If the client executes
multiple scan operations at the same time on the same process, then COM
will be initialized twice, eventually resulting in an error.

The error is `RPC_E_TOO_LATE`, which according to the Windows
documentation, means that COM was already initialized. This commit
workarounds the initialization error by catching this HRESULT and
assuming everything is fine, but the correct solution is to get rid of
COM altogether.

Change-Type: patch
Changelog-Entry: Fix "Couldn't initialize the scanner: An unknown error occurred" error.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Contributor

jviotti commented Jul 31, 2017

@barchard We eventually got to the bottom of it. The issue happens when there are multiple drivelist scans happen in parallel on the same process. COM is initialized globally for the current process, so when multiple scans happen at the same time, they both try to initialize COM at the same time, which eventually fails.

jviotti added a commit that referenced this issue Jul 31, 2017
We use global functions to initialize COM. If the client executes
multiple scan operations at the same time on the same process, then COM
will be initialized twice, eventually resulting in an error.

The error is `RPC_E_TOO_LATE`, which according to the Windows
documentation, means that COM was already initialized. This commit
workarounds the initialization error by catching this HRESULT and
assuming everything is fine, but the correct solution is to get rid of
COM altogether.

Change-Type: patch
Changelog-Entry: Fix "Couldn't initialize the scanner: An unknown error occurred" error.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@barchard
Copy link
Author

barchard commented Jul 31, 2017 via email

jviotti added a commit that referenced this issue Jul 31, 2017
Drivelist currently crashes if there is a virtual drive mounted. The
best solution I could find is to check the resulting error from
IOCTL_STORAGE_GET_DEVICE_NUMBER.

Change-Type: patch
Changelog-Entry: Fix "Couldn't scan the drives: An unknown error occurred" where there is a mounted virtual drive.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Aug 1, 2017
Drivelist currently crashes if there is a virtual drive mounted. The
best solution I could find is to check the resulting error from
IOCTL_STORAGE_GET_DEVICE_NUMBER.

Change-Type: patch
Changelog-Entry: Fix "Couldn't scan the drives: An unknown error occurred" where there is a mounted virtual drive.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Aug 1, 2017
We use global functions to initialize COM. If the client executes
multiple scan operations at the same time on the same process, then COM
will be initialized twice, eventually resulting in an error.

The error is `RPC_E_TOO_LATE`, which according to the Windows
documentation, means that COM was already initialized. This commit
workarounds the initialization error by catching this HRESULT and
assuming everything is fine, but the correct solution is to get rid of
COM altogether.

Change-Type: patch
Changelog-Entry: Fix "Couldn't initialize the scanner: An unknown error occurred" error.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Aug 1, 2017
We use global functions to initialize COM. If the client executes
multiple scan operations at the same time on the same process, then COM
will be initialized twice, eventually resulting in an error.

The error is `RPC_E_TOO_LATE`, which according to the Windows
documentation, means that COM was already initialized. This commit
workarounds the initialization error by catching this HRESULT and
assuming everything is fine, but the correct solution is to get rid of
COM altogether.

Change-Type: patch
Changelog-Entry: Fix "Couldn't initialize the scanner: An unknown error occurred" error.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Aug 1, 2017
Drivelist currently crashes if there is a virtual drive mounted. The
best solution I could find is to check the resulting error from
IOCTL_STORAGE_GET_DEVICE_NUMBER.

Change-Type: patch
Changelog-Entry: Fix "Couldn't scan the drives: An unknown error occurred" where there is a mounted virtual drive.
Fixes: #198
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@mubed
Copy link

mubed commented Aug 29, 2017

I still have this problem in Version 1.1.2 (Win7):
2017-08-29 09_07_32-error

@barchard
Copy link
Author

@mubed all of the discussions here have been in regards to version 5.0.22 and later. maybe update to the latest version? 1.1.2 sounds really old.

@mubed
Copy link

mubed commented Aug 29, 2017

Where can I get a newer version, when 1.1.2 is what you see on "etcher.io"?!
2017-08-29 11_36_49-etcher - internet explorer - __remote - __remote

@lurch
Copy link
Contributor

lurch commented Sep 11, 2017

@mubed v1.1.2 is the latest version of Etcher.
However one of the sub-components used within Etcher is drivelist (currently at v5.1.8), which is what this particular GH repo is about ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@barchard @lurch @rswamy @mubed @jviotti @DuskDweller @TanninOne and others