Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Referring to #683 (long read but important)
#683 reported that accessing certain properties (specifically Capabilities and Hash Algorithms) when the (async)client is not connected would cause a cross-Async->Sync call to (sync)Connect(). That analysis was correct (at that time).
This was a result of extensive code changes and additions in the async client.
The (rather quick) fix was to remove any call to connect() in the property getters.
Later on in the history of development, reconnects due to stale data and just generally allowing API calls without a preceeding connect led to a certain confusion about which APIs are needing a connect in the first place (or not).
#1698 Reported the errors that can occur when accessing properties without a prior connect.
Addressing these was a bit involved.
This PR brings back the premature removal of connect() calls in certain property getters and introduces a config setting to steer the availability of "automatic" (re-)connects. It overcomes the danger of a cross-Async->Sync call to (sync)Connect(), which was the original problem identified by #683, not by a quick fix of just removing the connect calls but rather coding them in such a way that correct functionality is guaranteed.
The new config setting:
The new config enum for
client.Config.SelfConnectMode
is the following and it keeps things ASIS as the default is "Always":As a second stage in the future, it will be necessary to migrate the two property getters, Capabilites and Hash Algorithms to be
methods instead of properties. Such a migration is also pending (as a further example) for the
IsConnected
property of theFTPSocketStream
.Such getters are not really supposed to invoke complex operations, although there is no formal rule against this. In all three cases (
FtpSocketStream.IsConnected
,client.Capabilites
,client.HashAlgorithms
) converting these to methods is quite involved).