Add Config.EagerConnect, so DialConfig can report a failure to connect - #76
Open
christhomas wants to merge 1 commit into
Open
Add Config.EagerConnect, so DialConfig can report a failure to connect#76christhomas wants to merge 1 commit into
christhomas wants to merge 1 commit into
Conversation
Fixes secsy#35. DialConfig is named like every other Dial in Go and behaves unlike them: it builds a client without connecting. A refused port, an unreachable host or a wrong password are therefore reported by whatever operation happens to run first — or by nothing at all, if the caller checked the error DialConfig returned and carried on, which is what the reporter did. DialConfig("127.0.0.1:62628") -> client, err = <nil> first operation -> connection refused EagerConnect opens one connection and logs in before returning, so both kinds of failure come back from DialConfig. The connection is returned to the pool rather than discarded, so the check costs a round trip and not a connection. Opt-in, defaulting to false, because changing DialConfig itself would break callers who rely on it being cheap — and the maintainer has said this belongs to a v2. This gets the behaviour to anyone who wants it now without spending that. Red before green: the bug was reproduced first (DialConfig returning a nil error for a port nothing was listening on), and the tests cover a refused port, a wrong password, that the default is still lazy, and that the connection opened by the check is not leaked.
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #35.
DialConfigis named like every otherDialin Go and behaves unlike them — it builds a client without connecting. Reproducing what the reporter hit:A refused port, an unreachable host or a wrong password are reported by whatever operation happens to run first — or by nothing at all, if the caller checks the error
DialConfigreturned and carries on.EagerConnectopens one connection and logs in before returning, so both kinds of failure come back fromDialConfig. The connection is handed back to the pool rather than discarded, so the check costs a round trip and not a connection.Why a flag and not a change to DialConfig
You wrote in the issue:
Agreed that changing
DialConfigitself is a v2 matter — callers rely on it being cheap. This is the opt-in version, defaulting to false, so the behaviour is available to anyone who wants it without spending the break. If v2 makes it the default, the field goes away with nothing else to unwind.Concretely, it removes a workaround: a downstream FTP driver of ours calls
Getwd()immediately afterDialConfigfor no reason other than to make a bad host fail at mount time.Tests
eager_connect_test.go— a refused port (no server needed; it binds a port and releases it, rather than guessing a number that might be filtered and hang), a wrong password, that the default is still lazy, and that the connection the check opens is not leaked.Independent of #71, #72, #73 and #75.