From b9cdb94f197ca2595742517bfcaee18e4a182e1b Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 5 Feb 2015 17:54:22 -0800 Subject: [PATCH] agent: Fixing setup of SCADA HTTP listener --- command/agent/http.go | 15 ++++++--------- command/agent/scada.go | 2 ++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/command/agent/http.go b/command/agent/http.go index e80b459a6e..bb46787b21 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -33,14 +33,10 @@ type HTTPServer struct { // NewHTTPServers starts new HTTP servers to provide an interface to // the agent. func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput io.Writer) ([]*HTTPServer, error) { - var tlsConfig *tls.Config - var list net.Listener - var httpAddr net.Addr - var err error var servers []*HTTPServer if config.Ports.HTTPS > 0 { - httpAddr, err = config.ClientListener(config.Addresses.HTTPS, config.Ports.HTTPS) + httpAddr, err := config.ClientListener(config.Addresses.HTTPS, config.Ports.HTTPS) if err != nil { return nil, err } @@ -54,7 +50,7 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput NodeName: config.NodeName, ServerName: config.ServerName} - tlsConfig, err = tlsConf.IncomingTLSConfig() + tlsConfig, err := tlsConf.IncomingTLSConfig() if err != nil { return nil, err } @@ -64,7 +60,7 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput return nil, fmt.Errorf("Failed to get Listen on %s: %v", httpAddr.String(), err) } - list = tls.NewListener(tcpKeepAliveListener{ln.(*net.TCPListener)}, tlsConfig) + list := tls.NewListener(tcpKeepAliveListener{ln.(*net.TCPListener)}, tlsConfig) // Create the mux mux := http.NewServeMux() @@ -86,7 +82,7 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput } if config.Ports.HTTP > 0 { - httpAddr, err = config.ClientListener(config.Addresses.HTTP, config.Ports.HTTP) + httpAddr, err := config.ClientListener(config.Addresses.HTTP, config.Ports.HTTP) if err != nil { return nil, fmt.Errorf("Failed to get ClientListener address:port: %v", err) } @@ -107,6 +103,7 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput return nil, fmt.Errorf("Failed to get Listen on %s: %v", httpAddr.String(), err) } + var list net.Listener if isSocket { // Set up ownership/permission bits on the socket file if err := setFilePermissions(socketPath, config.UnixSockets); err != nil { @@ -152,7 +149,7 @@ func NewHTTPServers(agent *Agent, config *Config, scada net.Listener, logOutput srv.registerHandlers(false) // Never allow debug for SCADA // Start the server - go http.Serve(list, mux) + go http.Serve(scada, mux) servers = append(servers, srv) } diff --git a/command/agent/scada.go b/command/agent/scada.go index b47b435caa..7fb8c42f9f 100644 --- a/command/agent/scada.go +++ b/command/agent/scada.go @@ -120,6 +120,8 @@ func (s *scadaListener) Push(conn net.Conn) error { select { case s.pending <- conn: return nil + case <-time.After(time.Second): + return fmt.Errorf("accept timed out") case <-s.closedCh: return fmt.Errorf("scada listener closed") }