Can Mercurial Detect and Handle Expired SSH or HTTP Credentials Without Requiring a New Connection?
0 reputation · 23 Nov 2021, 02:05 UTC
0 reputation · 23 Nov 2021, 02:05 UTC
The goal is to understand whether Mercurial can react to credential expiration that occurs during a long‑running operation such as a large push or pull, given that it delegates authentication to the underlying SSH or HTTP transport.
Mercurial itself does not enforce credential expiration; it relies on the transport layer to reject expired credentials, and its hooks (e.g., pretxnchangegroup) are invoked only after the transport authentication succeeds. This raises uncertainty about whether any mechanism exists to anticipate or mitigate an impending credential failure before the transport aborts the connection.
Does Mercurial provide a way to inspect credential validity prior to invoking a transport operation? Can a hook be configured to validate credential freshness without waiting for a transport‑level error? Is there any planned or experimental feature that would allow Mercurial to trigger a credential refresh mid‑session?
34775 reputation · 23 Nov 2021, 12:50 UTC
Mercurial does not have a built‑in way to detect or refresh expired SSH or HTTP credentials during an ongoing push or pull. It relies entirely on the underlying transport (SSH client or HTTP library) to perform authentication once per command, and it will abort the operation when that transport reports an authentication failure.
Because Mercurial delegates authentication to the transport layer, it only sees the result of that authentication after the transport has already succeeded or failed. There is no internal checkpoint where Mercurial can query the credential’s freshness before invoking the transport, and its hook system runs only after authentication succeeds, so hooks cannot pre‑empt a credential expiry.
pretxnchangegroup, incoming, or outgoing execute after transport authentication succeeds and therefore cannot be used to check credential freshness beforehand.ssh-agent with a timeout).hg push) and observe that the operation fails with an authentication error once the credential expires.If you are using an SSH agent that can reload keys without tearing down the underlying socket, note that Mercurial still sees the original authentication as valid until the transport reports an error; the agent’s internal refresh does not change Mercurial’s behavior.
To determine whether a specific SSH implementation keeps the connection alive while reloading keys, you would need to know the exact SSH client version and its keep‑alive/rekey behavior. This detail only changes the recommendation if you rely on that client’s ability to maintain a session; otherwise, the conclusion remains that Mercurial cannot handle credential expiration without reconnecting.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.