Use a httpClient with a default timeout
otherwise, notifications (http post request to the API) can stack forever if the server is not
responding.
see https://github.com/Sirupsen/logrus/pull/157#issuecomment-100245567
diff --git a/airbrake.go b/airbrake.go
index ab02d51..d5d5434 100644
--- a/airbrake.go
+++ b/airbrake.go
@@ -2,9 +2,11 @@
import (
"bytes"
+ "crypto/tls"
"errors"
"io/ioutil"
"log"
+ "net"
"net/http"
"os"
"reflect"
@@ -12,6 +14,7 @@
"runtime"
"sync"
"text/template"
+ "time"
)
var (
@@ -103,7 +106,23 @@
log.Printf("Airbrake payload for endpoint %s: %s", Endpoint, buffer)
}
- response, err := http.Post(Endpoint, "text/xml", buffer)
+ var httpClient = &http.Client{
+ Transport: &http.Transport{
+ Proxy: http.ProxyFromEnvironment,
+ Dial: (&net.Dialer{
+ Timeout: 30 * time.Second,
+ KeepAlive: 30 * time.Second,
+ }).Dial,
+ TLSHandshakeTimeout: 10 * time.Second,
+ TLSClientConfig: &tls.Config{
+ ClientSessionCache: tls.NewLRUClientSessionCache(1024),
+ },
+ MaxIdleConnsPerHost: 100,
+ ResponseHeaderTimeout: 10 * time.Second,
+ },
+ Timeout: 10 * time.Second,
+ }
+ response, err := httpClient.Post(Endpoint, "text/xml", buffer)
if err != nil {
log.Printf("Airbrake error: %s", err)
return err