spesmilo / electrum

Electrum Bitcoin Wallet
https://electrum.org
MIT License
7.42k stars 3.08k forks source link

Electrum for Windows 3.0.2 keeps renaming my wallet file #3452

Open bryanhbell opened 6 years ago

bryanhbell commented 6 years ago

Every time I close Electrum, it appends .tmp.#### (where # is some random digit) to the filename of my wallet file. The next time I open Electrum, it can't find my wallet file and presents me with an Install Wizard window with the error

The file does not exist. Press 'Next' to create this wallet, or choose another file.

I can use the Choose button to navigate to the renamed file and it will open my wallet. After closing again, however, it appends another .tmp#### to the filename.

For example, if my wallet file is named default_wallet, when I close Electrum, the file is renamed default_wallet.tmp.9124. The next time I open Electrum, it can't find defalut_wallet and gives me the error. So I navigate to default_wallet.tmp.9124 and open my wallet. When I close Electrum, the file is renamed again to default_wallet.tmp.9124.tmp.4847 and the whole process starts over the next time I launch Electrum.

I have tried installing a fresh copy of Electrum, but the issue persists.

I'm using Windows 7 Ultimate 64-bit with SP1. I checked to see if I was missing any Microsoft updates for my OS. There are no updates being offered in Windows Update right now. However, since Electrum's download page says:

Note: Some old versions of Windows might need to install the KB2999226 Windows update.

I tried installing that update. When I did I received the message that the update is not applicable to my computer.

My Electrum for Windows installation was performed using the Windows Installer file from the Electrum download page. The problem also occurs if I use the standalone executable.

My Windows username contains only ASCII letters, no diacritical or Cyrillic characters.

Any ideas what I'm doing wrong to cause this constant renaming? Please let me know if I can supply any further information to help resolve this issue.

bauerj commented 6 years ago

Are you able to rename the temporary wallet file back to the original name?

This looks like it's a permission issue. Electrum should move that file to the original location but apparently that doesn't work here.

bryanhbell commented 6 years ago

Yes, I can rename the temporary wallet file back to the original name. Electrum then opens it without trouble. Of course, after I close Electrum, the file gets renamed once again and the next time Electrum fails to find the file because the name has changed.

The original file and the renamed file that replaced it reside in the same directory: %APPDATA%\Electrum\wallets

I will check the permissions for the file and directory when I get a chance and report what I find here.

bryanhbell commented 6 years ago

I ran icacls on my wallet file. It has the following permissions:

BUILTIN\Administrators:(I)(F) NT AUTHORITY\SYSTEM:(I)(F) BUILTIN\Users:(I)(RX) NT AUTHORITY\Authenticated Users:(I)(M)

I tried temporarily giving Full Control permission to Everyone for the wallets directory (from which my wallet file inherits the above permissions), but the problem persists. The newly renamed file with the .tmp#### extension included the Everyone permissions I'd set. Running and closing Electrum again caused it to rename the file yet again by adding an additional .tmp#### extension to the one that was already present.

What permissions is Electrum expecting when it touches the wallet file?

SomberNight commented 6 years ago

This is what I have on Windows 10.0.15063:

> icacls .\wallets\test_std_asdsad
.\wallets\test_std_asdsad NT AUTHORITY\SYSTEM:(F)
                          BUILTIN\Administrators:(F)
                          USER\user:(F)
bryanhbell commented 6 years ago

I'm not sure whether USER\user in Windows 10 is analogous to Windows 7's BUILTIN\Users or NT AUTHORITY\Authenticated Users (or whether it's neither).

I tried temporarily assigning Full Control to BUILTIN\Users, but as I expected after my earlier experiment using Everyone, the problem persists.

I'm starting to think the cause of this issue might not be permissions-related after all.

HardCorePawn commented 6 years ago

Could this possibly be another process like a virus/malware scanner locking the file?

I've not seen Electrum generate .tmp### files before... but is it possible that the tmp file is being locked by another process when it is created, and then Electrum can't rename it before it shutdowns?

What happens if you open two wallets at the same time... and then close one of the wallets (but Electrum is still effectively running). Does the wallet file that gets closed stay as .tmp or does it close correctly?

chriswatt commented 6 years ago

Ran into the same issue, turned out it was dropbox that was preventing Electrum from writing the original filename and appending .tmp.####

Ignoring the security issue with storing your wallet in dropbox, I would assume @bryanhbell issue is somewhat similar, a process is locking the file whilst Electrum is trying to write.

bryanhbell commented 6 years ago

Sorry for my late response. I tried booting into safe mode and running Electrum. The problem did not occur. This leads me to believe that HardCorePawn may be correct that some process is locking the wallet file. It will take a little more experimentation to determine which process that might be. I do not have Dropbox installed on my PC. I will post here if I discover a process that is conflicting with Electrum.

silicontraption commented 6 years ago

Same problem here, same OS (Win7Pro-x64). I do have my Wallets in a DIFFERENT directory than the default. They are in a Dropbox folder. I suspected it was a Dropbox contention, but bryanhbell says he has this same problem without Dropbox....

I can rename and open, or just open the ones with the .tmp.xxxx extensions...but it's a crap shoot what I get when launching.

ElectronCash seems to have the same problem.

bryanhbell commented 6 years ago

I am still researching this issue.

I have tried stopping all services and ending all processes that Windows will permit me to stop or end. After doing so, the problem still occurs. So the problem probably isn't being caused by any program I have installed on my PC. It is more likely that a process that is part of Windows itself is causing the problem.

I have installed Process Monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to see which processes are touching my wallet file when the problem occurs. I can see two entries in which Electrum attempts to run the operation "SetRenameInformationFile" and the result is Access Denied. There are two other processes that touch the file when I shut down Electrum:

I am still trying to determine for sure if one of these (or something else) is causing the issue.

bryanhbell commented 6 years ago

MsMPEng.exe and SearchProtocolHost.exe do not appear to be causing the problem. I have disabled those processes and the problem still occurs. Now Process Monitor shows that Electrum is the only process that touches my wallet file when I exit Electrum.

bryanhbell commented 6 years ago

Updated to Electrum v3.0.5 today and confirmed the problem still occurs.

silicontraption commented 6 years ago

Thanks for chasing this Bryan. I happy that someone else has been able to confirm the issue.

Coding-Enthusiast commented 6 years ago

Someone reported the same problem on Ubuntu: https://bitcointalk.org/index.php?topic=2714897.0

strabadser commented 6 years ago

The issue on Ubuntu, as described on Bitcoin Talk, is similar, not quite the same.

bauerj commented 6 years ago

I don't think there's anything we can do to prevent this issue. If we wouldn't rename the file after it has been written, we would risk saving only parts of the wallet file and thus corrupting it.

bryanhbell commented 6 years ago

I have found the cause of my problem. It turns out that Electrum is having a problem interacting with Windows' User Account Control (UAC) feature. When I run Electrum, it runs using my user account for permissions. My user account is an Administrator type account and a member of the BUILTIN\Administrators user group. That gives my user account full administrator privileges, except when UAC is enabled (which it is on my computer). When UAC is enabled, my user account behaves as a Standard (non-Administrator) type account for most functions until Administrator permissions are required. When that happens, I am given a visual prompt to approve my account's temporary use of Administrator permissions.

While running, Electrum writes changes to my wallet in a temporary copy of my wallet file. Upon closing (provided there were any changes to my wallet) Electrum attempts to save its temp file with the same name as my wallet file, overwriting my old file with the temporary copy.

When UAC is enabled, however, Electrum (running using my user account) doesn't have permission to overwrite my old wallet file. This is why Process Monitor was seeing the task SetRenameInformationFile returning the result "Access Denied". Unable to replace my old wallet file using the same name, Electrum deletes my old wallet file and saves a new wallet file with a modified name (using the .tmp### extension).

There are two temporary workarounds to this problem:

  1. Turn off UAC. This isn't optimal because it leaves my computer vulnerable to exploits that would make changes to my files without notifying me.

  2. Launch the Electrum executable file with the "Run As Administrator" option. I can do this in one of two ways:

a. Every time I launch Electrum, I can do so by right-clicking on the executable and choosing "Run As Administrator" in the pop-up context menu. Workable, but a bit tedious.

b. Open the Properties for the Electrum executable and on the Compatibility tab check "Run this program as an administrator". Every time I run Electrum after making this change, I will see a visual prompt asking me to approve giving Electrum Administrator privileges before it launches.

Electrum probably could be modified to work correctly with Windows' User Account Control system. See https://msdn.microsoft.com/en-us/library/aa905330.aspx.

Even if that weren't possible, Electrum could at least offer an error message when SetRenameInformationFile returns the "Access Denied" result. It would have been more helpful in troubleshooting this problem if Electrum displayed an error message explaining that Electrum couldn't properly save the wallet file using its original name due to a permissions problem.

I expect this issue should occur in Windows Vista, 7, 8, and 10, all of which utilize UAC.

bauerj commented 6 years ago

Thanks for troubleshooting.

Is there anything else you need to do to reproduce this error? I'm using Windows with an admin account and UAC enabled but I never had this kind of issue.

bryanhbell commented 6 years ago

Hmm. No, as far as I know there isn't anything else I need to do to reproduce the error. I'm surprised that you are not seeing the problem given your similar situation. Perhaps there is something else I'm not aware of about my Windows/Electrum setup that is contributing to the problem. I'm not sure what that could be. Perhaps I'll try installing Electrum on a few other Windows machines (virtual or real) to see if I can reproduce the problem.