spesmilo / spesmilo/electrum

Cannot connect to any server on Windows when there is a blockchain fork, Maximum Path Length (260 chars) exceeded

Open
#8,729 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OS-windows 🪟
Dominant language
Python
Stars
8.6k
Forks
3.5k
Avg merge
2d 8h
Merged PRs (30d)
61

Description

zib reported on irc that electrum 4.4.6 on Windows refuses to connect to any servers.

log:

20231205T010730.413560Z |    ERROR | interface.[blackie.c3-soft.com:57002] | Exception in run: OSError(22, 'Invalid argument')
Traceback (most recent call last):
  File "electrum\util.py", line 1311, in wrapper
  File "electrum\interface.py", line 516, in wrapper_func
  File "electrum\interface.py", line 539, in run
  File "electrum\interface.py", line 693, in open_session
  File "aiorpcx\curio.py", line 297, in __aexit__
  File "electrum\util.py", line 1482, in join
  File "electrum\interface.py", line 763, in run_fetch_blocks
  File "electrum\interface.py", line 782, in _process_header_at_tip
  File "electrum\interface.py", line 836, in step
  File "electrum\util.py", line 1340, in func_wrapper
  File "electrum\blockchain.py", line 457, in save_header
  File "electrum\blockchain.py", line 367, in swap_with_parent
  File "electrum\blockchain.py", line 385, in _swap_with_parent
  File "electrum\util.py", line 1340, in func_wrapper
  File "electrum\blockchain.py", line 598, in get_chainwork
  File "electrum\blockchain.py", line 513, in get_hash
  File "electrum\util.py", line 1340, in func_wrapper
  File "electrum\blockchain.py", line 472, in read_header
OSError: [Errno 22] Invalid argument

This line:
https://github.com/spesmilo/electrum/blob/1ca05f32435a23e561841e1b620b1c7620c29d83/electrum/blockchain.py#L472

So likely there was a blockchain fork at the time (or at least a stuck server), and the client was tracking these forks.
Now on Windows, the MAX_PATH on the filesystem is traditionally 260 characters.
We burn a lot of that space when naming the fork files, just that file itself can use up to ~140 characters:
https://github.com/spesmilo/electrum/blob/1ca05f32435a23e561841e1b620b1c7620c29d83/electrum/blockchain.py#L336-L337
OP said they were using the portable exe, and the exe was placed in "an encrypted drive using cryptomator so the path becomes fairly long". (When debugging this, moving the exe to C:/tmp/ resolved the issue)

As a result, the user-visible effect was the client not able to connect to any servers.


Note: on modern Windows, there is a way around the MAX_PATH limitation:

https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later

Enable Long Paths in Windows 10, Version 1607, and Later

Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.

To enable the new long path behavior, both of the following conditions must be met:

  • The registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD) must exist and be set to 1.
  • The application manifest must also include the longPathAware element.

pyinstaller does the second thing for us (https://github.com/pyinstaller/pyinstaller/pull/5424), so it is up to the user to set the registry key. (but this is obviously just an inconvenient workaround)


I am not sure if we can or want to fix this, just logging this issue for future reference.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in electrum/blockchain.py at the read_header and fork-file naming locations linked in the report, then reproduce the failure with the portable executable under a long Windows path. Compare it with running from C:/tmp/ and determine whether the project should handle the path-length failure differently; done means the intended fix or limitation is documented and the connection failure is addressed or clearly bounded.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.