From 9f219badab92cb3d018d7945b04177680767d258 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Sun, 10 Apr 2016 01:36:52 +0000 Subject: [PATCH] Stop using the httputil client for plugins * It sends unexpected TCP RSTs (causing connection reset by peer errors in the python plugin) Exception happened during processing of request from Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "./http-requests.py", line 145, in finish_request self.RequestHandlerClass(request, '-', self) File "/usr/lib/python2.7/SocketServer.py", line 658, in __init__ self.handle() File "/usr/lib/python2.7/BaseHTTPServer.py", line 349, in handle self.handle_one_request() File "/usr/lib/python2.7/BaseHTTPServer.py", line 312, in handle_one_request self.raw_requestline = self.rfile.readline(65537) File "/usr/lib/python2.7/socket.py", line 480, in readline data = self._sock.recv(self._rbufsize) error: [Errno 104] Connection reset by peer * It doesn't reuse connections --- probe/plugins/registry.go | 2 +- probe/plugins/unix_round_tripper.go | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/probe/plugins/registry.go b/probe/plugins/registry.go index 64967024c..fb5f3c5cf 100644 --- a/probe/plugins/registry.go +++ b/probe/plugins/registry.go @@ -290,7 +290,7 @@ func (p *Plugin) get(path string, params url.Values, result interface{}) error { // Context here lets us either timeout req. or cancel it in Plugin.Close ctx, cancel := context.WithTimeout(p.context, pluginTimeout) defer cancel() - resp, err := ctxhttp.Get(ctx, p.client, fmt.Sprintf("unix://%s?%s", path, params.Encode())) + resp, err := ctxhttp.Get(ctx, p.client, fmt.Sprintf("http://plugin%s?%s", path, params.Encode())) if err != nil { return err } diff --git a/probe/plugins/unix_round_tripper.go b/probe/plugins/unix_round_tripper.go index 0bbd49b51..1220df9d4 100644 --- a/probe/plugins/unix_round_tripper.go +++ b/probe/plugins/unix_round_tripper.go @@ -3,25 +3,14 @@ package plugins import ( "net" "net/http" - "net/http/httputil" "time" ) -type unixRoundTripper struct { - address string - timeout time.Duration -} - func makeUnixRoundTripper(address string, timeout time.Duration) (http.RoundTripper, error) { - return unixRoundTripper{address: address, timeout: timeout}, nil -} - -func (t unixRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - conn, err := net.DialTimeout("unix", t.address, t.timeout) - if err != nil { - return nil, err + rt := &http.Transport{ + Dial: func(proto, addr string) (conn net.Conn, err error) { + return net.DialTimeout("unix", address, timeout) + }, } - client := httputil.NewClientConn(conn, nil) - defer client.Close() - return client.Do(req) + return rt, nil }