mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 20:11:09 +00:00
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
This commit is contained in:
committed by
Paul Bellamy
parent
2da13da6f7
commit
9f219badab
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user