spesmilo / electrum

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

[Bug] Electrum hangs and does not open on macOS Monterey 12.2 #7742

Open 3raxton opened 2 years ago

3raxton commented 2 years ago

Hey there @spesmilo, thanks for your hard work on Electrum. I've recently downloaded 4.2.0 and cannot get Electrum to open on my Mac running Monterey 12.2. I tried downloaded a few previous versions and running them and they all end up causing Electrum to be stuck not responding.

Is there a workaround to this or something that I should do to ensure that Electrum will open? Again, thanks for your hard work!

SomberNight commented 2 years ago

Could you try running from the terminal with the -v flag, to get some logs, e.g.:

$ /Applications/Electrum.app/Contents/MacOS/run_electrum -v

Has electrum ever worked for you on this PC or is this your first time trying? Not sure if relevant but is your mac intel- or arm-based?

3raxton commented 2 years ago

Sure thing, thanks for the command. Below are the errors for a quick read and the and full output.

Errors:

FileNotFoundError: [Errno 2] No such file or directory: '/Users/Prized/.electrum/config'

SyntaxError: invalid or missing encoding declaration for '/Applications/Electrum.app/Contents/MacOS/run_electrum'

SyntaxError: invalid or missing encoding declaration for '/Applications/Electrum.app/Contents/MacOS/run_electrum' [91152] Failed to execute script run_electrum

Full output:

I | simple_config.SimpleConfig | electrum directory /Users/Prized/.electrum
I | logging | Electrum version: 4.2.0 - https://electrum.org - https://github.com/spesmilo/electrum
I | logging | Python version: 3.9.10 (v3.9.10:f2f3f53782, Jan 13 2022, 17:02:14) 
[Clang 6.0 (clang-600.0.57)]. On platform: macOS-10.16-x86_64-i386-64bit
I | logging | Logging to file: None
I | logging | Log filters: verbosity '*', verbosity_shortcuts ''
I/p | plugin.Plugins | registering hardware bitbox02: ('hardware', 'bitbox02', 'BitBox02')
I/p | plugin.Plugins | registering hardware coldcard: ('hardware', 'coldcard', 'Coldcard Wallet')
I/p | plugin.Plugins | registering hardware digitalbitbox: ('hardware', 'digitalbitbox', 'Digital Bitbox wallet')
I/p | plugin.Plugins | registering hardware keepkey: ('hardware', 'keepkey', 'KeepKey wallet')
I/p | plugin.Plugins | registering hardware ledger: ('hardware', 'ledger', 'Ledger wallet')
I/p | plugin.Plugins | registering hardware safe_t: ('hardware', 'safe_t', 'Safe-T mini wallet')
I/p | plugin.Plugins | registering hardware trezor: ('hardware', 'trezor', 'Trezor wallet')
I/p | plugin.Plugins | registering wallet type ('2fa', 'trustedcoin')
D | util.profiler | Plugins.__init__ 0.0159
I/n | network | blockchains [0]
--- Logging error ---
Traceback (most recent call last):
  File "run_electrum", line 393, in main
  File "run_electrum", line 409, in handle_cmd
  File "electrum/util.py", line 439, in <lambda>
  File "electrum/util.py", line 435, in do_profile
  File "electrum/daemon.py", line 472, in __init__
  File "electrum/network.py", line 289, in __init__
  File "electrum/network.py", line 1147, in _set_preferred_chain
  File "electrum/simple_config.py", line 170, in set_key
  File "electrum/simple_config.py", line 179, in _set_key_in_user_config
  File "electrum/simple_config.py", line 271, in save_user_config
FileNotFoundError: [Errno 2] No such file or directory: '/Users/Prized/.electrum/config'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tokenize.py", line 330, in find_cookie
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 0: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "logging/__init__.py", line 1083, in emit
  File "logging/__init__.py", line 927, in format
  File "electrum/logging.py", line 38, in format
  File "logging/__init__.py", line 671, in format
  File "logging/__init__.py", line 621, in formatException
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 103, in print_exception
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 517, in __init__
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 366, in extract
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 288, in line
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/linecache.py", line 30, in getline
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/linecache.py", line 46, in getlines
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/linecache.py", line 136, in updatecache
  File "tokenize.py", line 394, in open
  File "tokenize.py", line 371, in detect_encoding
  File "tokenize.py", line 335, in find_cookie
SyntaxError: invalid or missing encoding declaration for '/Applications/Electrum.app/Contents/MacOS/run_electrum'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tokenize.py", line 330, in find_cookie
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 0: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "run_electrum", line 476, in <module>
  File "run_electrum", line 399, in main
  File "logging/__init__.py", line 1481, in exception
  File "logging/__init__.py", line 1475, in error
  File "logging/__init__.py", line 1589, in _log
  File "logging/__init__.py", line 1599, in handle
  File "logging/__init__.py", line 1661, in callHandlers
  File "logging/__init__.py", line 952, in handle
  File "logging/__init__.py", line 1091, in emit
  File "logging/__init__.py", line 1005, in handleError
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 103, in print_exception
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 533, in __init__
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 545, in _load_lines
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 545, in _load_lines
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 543, in _load_lines
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/traceback.py", line 288, in line
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/linecache.py", line 30, in getline
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/linecache.py", line 46, in getlines
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/linecache.py", line 136, in updatecache
  File "tokenize.py", line 394, in open
  File "tokenize.py", line 371, in detect_encoding
  File "tokenize.py", line 335, in find_cookie
SyntaxError: invalid or missing encoding declaration for '/Applications/Electrum.app/Contents/MacOS/run_electrum'
[91152] Failed to execute script run_electrum
I/p | plugin.Plugins | stopped 

Exception ignored in: <module 'threading' from '/Applications/Electrum.app/Contents/MacOS/threading.pyc'>
Traceback (most recent call last):
  File "threading.py", line 1470, in _shutdown
KeyboardInterrupt: 

For reference, I am running the packaged .dmg downloaded from electrum.org. Electrum has worked on previous Macs that I've owned, all intel based. I also believe that Electrum has run on this Mac before, probably over a year ago.

Thanks for your help @SomberNight

SomberNight commented 2 years ago

That whole trace is just weird... thanks for sharing it.

FileNotFoundError: [Errno 2] No such file or directory: '/Users/Prized/.electrum/config'

Maybe try renaming the data directory to let electrum start fresh and recreate it:

$ mv $HOME/.electrum $HOME/.electrum2
3raxton commented 2 years ago

This works, I appreciate the info. However, it does not restore with the previous wallet. Is there any way to do this aside from the seed words / master key? On Mar 26, 2022, 13:39 -0500, spesmilo/electrum @.***>, wrote:

mv $HOME/.electrum $HOME/.electrum2

SomberNight commented 2 years ago

Sure, you can manually copy the wallet files from the old folder to the new one (inside the wallets folder in the datadir).

Please don't delete the old datadir (especially without backing up the wallets inside :P) for now. It would be great if we could figure out the root cause of the issue. There must be something weird with the existing/original datadir you had.

Could you share the outputs of $ ls -la $HOME/.electrum and $ ls -la $HOME/.electrum2?

3raxton commented 2 years ago

Thanks for letting me know, I'm a bit confused though. Can you help me figure out where the wallets folder is located? If I'm understanding it would be within datadir but this is something I cannot find anywhere.

Here is the output of the commands.

$ ls -la $HOME/.electrum

ls: /Users/Prized/.electrum: No such file or directory

$ ls -la $HOME/.electrum2

total 2080
drwx------   12 Prized  staff       384 Mar 26 13:52 .

drwxr-xr-x@ 170 Prized  staff      5440 Mar 26 14:01 ..

drwxr-xr-x   11 Prized  staff       352 Mar 26 12:26 .electrum2

-rw-r--r--    1 Prized  staff  58331600 Mar 26 13:59 blockchain_headers

drwx------    2 Prized  staff        64 Mar 26 13:43 cache

drwx------   26 Prized  staff       832 Mar 26 13:54 certs

-rw-------    1 Prized  staff       270 Mar 26 13:44 config

-rw-r--r--    1 Prized  staff        72 Mar 26 13:52 daemon

srwxr-xr-x    1 Prized  staff         0 Mar 26 13:52 daemon_rpc_socket

drwx------    2 Prized  staff        64 Mar 26 13:43 forks

-rw-r--r--    1 Prized  staff       549 Mar 26 13:54 recent_servers

drwx------    2 Prized  staff        64 Mar 26 13:52 wallets
SomberNight commented 2 years ago

Thanks for letting me know, I'm a bit confused though. Can you help me figure out where the wallets folder is located? If I'm understanding it would be within datadir but this is something I cannot find anywhere.

By datadir I am just shortening "data directory", and that is the main folder in question here, i.e. by default on mac it is located at $HOME/.electrum. Note that based on your previous pastes, in your case $HOME=/Users/Prized. When you start Electrum, it checks if /Users/Prized/.electrum/ exists, and if not, creates it. That is where it puts everything. The wallets are located in /Users/Prized/.electrum/wallets/ (this folder is also visible in the last line of your previous comment btw).

Please don't manually change parts of the commands you run and their outputs to HOME/$HOME, unless you are sure what that means, as it's making it harder to understand them. For example, in the output of ls, your username should appear, not the home directory path. (and your username is already "leaked" so no point in redacting it now :) )

$ ls -la $HOME/.electrum2
total 2080
drwx------   12 $HOME  staff       384 Mar 26 13:52 .

Looking at the outputs of ls, I am confused. The command I had originally written above ($ mv $HOME/.electrum $HOME/.electrum2) renames the .electrum folder, i.e. rename from /Users/Prized/.electrum to /Users/Prized/.electrum2. The goal was to let Electrum re-create a fresh data directory at /Users/Prized/.electrum (while the existing one is kept next to it but is left untouched). However, based on the output of ls above, it looks like you have another folder at /Users/Prized/.electrum2/.electrum2... So I am confused at what you did :/

3raxton commented 2 years ago

Hey there,

Thanks for the time to share this info with me. I've changed the past comments to make sure that they make more sense. I hope that creates a bit more clarity.

/Users/Prized/.electrum2 does exist but the wallets folder is empty. However, you're exactly right that /Users/Prized/.electrum2/.electrum2 exists and has the wallets I used with Electrum. What should I do with those.

Thanks again for the help and clarity as well as tips on best practices! I appreciate it :)

SomberNight commented 2 years ago

you're exactly right that /Users/Prized/.electrum2/.electrum2 exists and has the wallets I used with Electrum

(close Electrum if it is running, and then:) First of all, make a copy of those wallets (or the whole wallets folder), as a backup.

Ok, so assuming you haven't created valuable new wallets since opening this issue, let's try to restore the original state first and delete a whole bunch of things...

$ rm -rf /Users/Prized/.electrum
$ mv /Users/Prized/.electrum2/.electrum2 /Users/Prized/.electrum
$ rm -rf /Users/Prized/.electrum2

So now you should have only a single copy of the datadir, and it is at the expected location /Users/Prized/.electrum. AFAIU this should be the state you were in when opening the issue. Try to see if running Electrum reproduces the original issue; hopefully it does! :P

Assuming it does, with Electrum not running, run:

$ mv /Users/Prized/.electrum /Users/Prized/.electrum_original

Try running Electrum now, it should create a fresh directory at /Users/Prized/.electrum.

Assuming it does, and it does not crash, close Electrum, and now at this state I would be curious how the file permissions compare between the two folders:

$ ls -la /Users/Prized/.electrum
$ ls -la /Users/Prized/.electrum_original

^ so please share the outputs of those commands.

Now, you can e.g. manually copy your wallet files from either your backup or from /Users/Prized/.electrum_original/wallets/ into /Users/Prized/.electrum/wallets and start using them again. (note that most settings would have to be manually configured again)

3raxton commented 2 years ago

Thank you for your time and dedication. This solves the problem and cleans up the mess I created; I appreciate your willingness to help me out! The output of the commands you shared follow.

ls -la /Users/Prized/.electrum:

total 2072
drwx------   10 Prized  staff       320 Mar 27 22:14 .
drwxr-xr-x@ 171 Prized  staff      5472 Mar 27 22:14 ..
-rw-r--r--    1 Prized  staff  58346320 Mar 27 22:14 blockchain_headers
drwx------    2 Prized  staff        64 Mar 27 22:14 cache
drwx------   10 Prized  staff       320 Mar 27 22:14 certs
-rw-------    1 Prized  staff       270 Mar 27 22:14 config
srwxr-xr-x    1 Prized  staff         0 Mar 27 22:14 daemon_rpc_socket
drwx------    2 Prized  staff        64 Mar 27 22:14 forks
-rw-r--r--    1 Prized  staff       285 Mar 27 22:14 recent_servers
drwx------    2 Prized  staff        64 Mar 27 22:14 wallets

ls -la /Users/Prized/.electrum_original:

total 74336
drwxr-xr-x   12 Prized  staff       384 Mar 27 22:13 .
drwxr-xr-x@ 171 Prized  staff      5472 Mar 27 22:14 ..
-rw-r--r--@   1 Prized  staff      6148 Mar 26 18:06 .DS_Store
-rw-r--r--    1 Prized  staff  58331360 Mar 26 13:28 blockchain_headers
-rw-r--r--    1 Prized  staff  23887872 Sep 18  2017 blockchain_headers.tmp
drwx------    2 Prized  staff        64 Dec 30  2019 cache
drwxr-xr-x  235 Prized  staff      7520 Mar 26 13:29 certs
lrwxr-xr-x    1 Prized  staff        45 Aug  4  2020 config -> /Users/Prized/Dropbox/Mackup/.electrum/config
-rw-r--r--    1 Prized  staff         0 Mar 27 22:13 daemon
drwxr-xr-x    2 Prized  staff        64 Sep 18  2017 forks
-rw-r--r--    1 Prized  staff       720 Mar 26 13:29 recent_servers
drwxr-xr-x    7 Prized  staff       224 Mar 27 20:11 wallets

Thanks again for your guidance and support. Be well!

SomberNight commented 2 years ago

lrwxr-xr-x 1 Prized staff 45 Aug 4 2020 config -> /Users/Prized/Dropbox/Mackup/.electrum/config

So looks like in your old electrum folder the config file is symlink to something in dropbox -- I suppose you have done that manually so that it would be automatically backed up? Maybe you have deleted dropbox since or moved things around...?

Could you run $ ls -la /Users/Prized/Dropbox/Mackup/.electrum/config just to see if that file still exists and what permissions it has?

3raxton commented 2 years ago

This wasn't exactly caused manually, it was done by Mackup which is used to keep Mac application settings in sync. Unintentionally backed up but that is where it was moved to as a dotfile.

When running $ ls -la /Users/Prized/Dropbox/Mackup/.electrum/config the result is:

ls: /Users/Prized/Dropbox/Mackup: No such file or directory

This is because Mackup was uninstalled a few years ago and the Dropbox as well as Mackup directories no longer exist.