Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to connect to agent: address https://192.168.1.10:8080: too many colons in address #4358

Closed
jackyhome0801 opened this issue Jul 9, 2018 · 1 comment
Milestone

Comments

@jackyhome0801
Copy link

jackyhome0801 commented Jul 9, 2018

Overview of the Issue

i got below issues when i run consul agent
"
Failed to connect to agent: address https://10.180.10.40:8088: too many colons in address
"

Reproduction Steps

1, config consul with TLS, for example, ip is 192.168.1.10, port is 8080
"addresses": {
"https": "192.168.1.10"
},
"ports": {
"https": 8080
},

2, put a watch file under consul config dir, just a example, it's not the matter
{
"type": "key",
"key": "foo/bar/baz",
"handler_type": "script",
"args": ["/usr/bin/my-service-handler.sh", "-redis"]
}

3, run consul agent

then, we can see error logs as below
"
agent: Failed to run watch: Failed to connect to agent: address https://10.180.10.40:8088: too many colons in address
"

source code

when i check source code git log, i found agent/agent.go has added some code as below

commit 8e0e239
Author: Matt Keeler mjkeeler7@gmail.com
Date: Thu May 31 17:07:36 2018 -0400

Allow passing in a config to the watch plan to use when creating the API client                                          
                                                                                                                         
This allows watches from consul agent config (rather than consul watch command) to be able to utilize HTTPs              

diff --git a/agent/agent.go b/agent/agent.go
index 20f5a1c..d6b3eab 100644
--- a/agent/agent.go
+++ b/agent/agent.go
@@ -646,14 +646,19 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error {

    // Determine the primary http(s) endpoint.                                                                           
    var netaddr net.Addr                                                                                                 
   https := false                                                                                                       
    if len(cfg.HTTPAddrs) > 0 {                                                                                          
            netaddr = cfg.HTTPAddrs[0]                                                                                   
    } else {                                                                                                             
            netaddr = cfg.HTTPSAddrs[0]                                                                                  
           https = true                                                                                                 
    }                                                                                                                    
    addr := netaddr.String()                                                                                             
    if netaddr.Network() == "unix" {                                                                                     
            addr = "unix://" + addr                                                                                      
           https = false                                                                                                
   } else if https {                                                                                                    
           addr = "https://" + addr                                                                               
    }                                                                                                                    

code analysis

net.SplitHostPort will be invoked in SetupTLSConfig (api.go), this interface split hostport like 127.0.0.1:8080 into host 127.0.0.1 and port 8080
but if a prefix is added ( addr = "https://" + addr ) , the result of perform net.SplitHostPort("https://127.0.0.1:8080") will be an error of
"
too many colons in address
"

@mkeeler
Copy link
Member

mkeeler commented Jul 9, 2018

@jackyhome0801 Thanks for the report (and tracking down the root cause).

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

No branches or pull requests

2 participants