mirror of
https://github.com/zrepl/zrepl.git
synced 2025-08-14 17:18:25 +02:00
prevent transient zrepl status error: Post "http://unix/status": EOF
See the comment added to client.go in this commit. fixes https://github.com/zrepl/zrepl/issues/483 fixes https://github.com/zrepl/zrepl/issues/262 fixes https://github.com/zrepl/zrepl/issues/379 fixes https://github.com/zrepl/zrepl/issues/379
This commit is contained in:
@ -14,11 +14,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
h http.Client
|
h *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(network, addr string) (*Client, error) {
|
func New(network, addr string) (*Client, error) {
|
||||||
httpc, err := controlHttpClient(func(_ context.Context) (net.Conn, error) { return net.Dial(network, addr) })
|
httpc, err := makeControlHttpClient(func(_ context.Context) (net.Conn, error) { return net.Dial(network, addr) })
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -63,8 +63,8 @@ func (c *Client) SignalReset(job string) error {
|
|||||||
return c.signal(job, "reset")
|
return c.signal(job, "reset")
|
||||||
}
|
}
|
||||||
|
|
||||||
func controlHttpClient(dialfunc func(context.Context) (net.Conn, error)) (client http.Client, err error) {
|
func makeControlHttpClient(dialfunc func(context.Context) (net.Conn, error)) (client *http.Client, err error) {
|
||||||
return http.Client{
|
return &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||||
return dialfunc(ctx)
|
return dialfunc(ctx)
|
||||||
@ -73,14 +73,24 @@ func controlHttpClient(dialfunc func(context.Context) (net.Conn, error)) (client
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonRequestResponse(c http.Client, endpoint string, req interface{}, res interface{}) error {
|
func jsonRequestResponse(c *http.Client, endpoint string, req interface{}, res interface{}) error {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
encodeErr := json.NewEncoder(&buf).Encode(req)
|
encodeErr := json.NewEncoder(&buf).Encode(req)
|
||||||
if encodeErr != nil {
|
if encodeErr != nil {
|
||||||
return encodeErr
|
return encodeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.Post("http://unix"+endpoint, "application/json", &buf)
|
hreq, err := http.NewRequest("POST", "http://unix"+endpoint, &buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hreq.Header.Set("Content-Type", "application/json")
|
||||||
|
// Prevent EOF errors when client request frequency and server keepalive close are at the same time.
|
||||||
|
// Found this by watching http.Server.ConnState changes, then found
|
||||||
|
// https://stackoverflow.com/questions/17714494/golang-http-request-results-in-eof-errors-when-making-multiple-requests-successi
|
||||||
|
// Note: The issue seems even more prounounced with local TCP sockets than unix domain sockets. So, I used that for debugging.
|
||||||
|
hreq.Close = true
|
||||||
|
resp, err := c.Do(hreq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ Developers should consult the git commit log or GitHub issue tracker.
|
|||||||
But the metric *value* is now the Unix timestamp at the time the daemon was started.
|
But the metric *value* is now the Unix timestamp at the time the daemon was started.
|
||||||
The Grafana dashboard in :repomasterlink:`dist/grafana` has been updated.
|
The Grafana dashboard in :repomasterlink:`dist/grafana` has been updated.
|
||||||
|
|
||||||
|
* |bugfix| transient zrepl status error: ``Post "http://unix/status": EOF``
|
||||||
|
|
||||||
0.5
|
0.5
|
||||||
---
|
---
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user