Skip to content

Set cachable to false - #60

Closed
benrutter wants to merge 2 commits into
fsspec:mainfrom
benrutter:main
Closed

Set cachable to false#60
benrutter wants to merge 2 commits into
fsspec:mainfrom
benrutter:main

Conversation

@benrutter

Copy link
Copy Markdown
Contributor

Closes issue #42

At the moment, because SSHFS is considered cachable, creating a new filesystem doesn't create a new connection, and maintains the old one.

That's probably not a good fit for SFTP connections, since they're likely to timeout and be closed off after a while, so almost any long running process using SSHFS is eventually going to hit an issue where the filesystem continues to reference a closed off connection, and the cache needs to be manually cleared.

To fix that, I've just set "cachable" to False here, so that creating a new filesystem would also bring in a new connection.

Honestly, I don't have the knowledge to know the full implications of this, but my main thoughts are:

  • Does this mean it's worth adding in something to clean up / close the connection when the SSHFS object goes out of memory? (otherwise there are potentially open but unusable connections floating around)
  • Is there a case where you'd want it to be cachable? In which case, the "cachable" setting could theoretically be put behind an __init__ argument? (my guess is that'd cause some kind of side effects nobody is expecting though)

@shcheklein

Copy link
Copy Markdown
Collaborator

Thanks for digging into this @benrutter — the diagnosis (cached instances outliving their connections) is right, but after testing this change we're closing it, for two reasons:

  1. As written it's a no-op: fsspec's instance cache lives in the _Cached metaclass, which checks the class attribute cls.cachable both when looking up and when storing instances — an instance attribute set inside __init__ is invisible to it. Verified empirically: with this patch applied, constructing SSHFileSystem twice with the same arguments still returns the same cached object.

  2. The working variant (cachable = False as a class attribute) would be the wrong default: every construction would pay a fresh SSH handshake (hundreds of ms), a heavy ecosystem-wide cost — DVC and fsspec.open() construct filesystems repeatedly and rely on the instance cache.

The underlying problem has working knobs today:

  • SSHFileSystem(host, keepalive_interval=30) — asyncssh keepalives (forwarded by sshfs) prevent idle connections from being dropped, which is the Initialisation seems to maintain cached filesystem #42 scenario,
  • SSHFileSystem(..., skip_instance_cache=True) — per-instance opt-out when you genuinely want a fresh connection,
  • SSHFileSystem.clear_instance_cache() — recovery in long-lived processes.

See #42 for the full guidance.

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

Successfully merging this pull request may close these issues.

2 participants