aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/graceful/server.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/graceful/server.go b/modules/graceful/server.go
index c5021a9ba5..26195c6322 100644
--- a/modules/graceful/server.go
+++ b/modules/graceful/server.go
@@ -28,6 +28,9 @@ var (
DefaultMaxHeaderBytes int
)
+// PerWriteWriteTimeout timeout for writes
+const PerWriteWriteTimeout = 5 * time.Second
+
func init() {
DefaultMaxHeaderBytes = 0 // use http.DefaultMaxHeaderBytes - which currently is 1 << 20 (1MB)
}
@@ -250,6 +253,13 @@ type wrappedConn struct {
closed *int32
}
+func (w wrappedConn) Write(p []byte) (n int, err error) {
+ if PerWriteWriteTimeout > 0 {
+ _ = w.Conn.SetWriteDeadline(time.Now().Add(PerWriteWriteTimeout))
+ }
+ return w.Conn.Write(p)
+}
+
func (w wrappedConn) Close() error {
if atomic.CompareAndSwapInt32(w.closed, 0, 1) {
defer func() {