derp: use a write timeout when sending to clients
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>pull/180/head
parent
ef5b09563f
commit
656b6f3fd3
|
@ -38,6 +38,10 @@ type Server struct {
|
||||||
// second to cap per-client reads at.
|
// second to cap per-client reads at.
|
||||||
BytesPerSecond int
|
BytesPerSecond int
|
||||||
|
|
||||||
|
// WriteTimeout, if non-zero, specifies how long to wait
|
||||||
|
// before failing when writing to a client.
|
||||||
|
WriteTimeout time.Duration
|
||||||
|
|
||||||
privateKey key.Private
|
privateKey key.Private
|
||||||
publicKey key.Public
|
publicKey key.Public
|
||||||
logf logger.Logf
|
logf logger.Logf
|
||||||
|
@ -306,6 +310,9 @@ func (c *sclient) handleFrameSendPacket(ctx context.Context, ft frameType, fl ui
|
||||||
}
|
}
|
||||||
|
|
||||||
dst.mu.Lock()
|
dst.mu.Lock()
|
||||||
|
if s.WriteTimeout != 0 {
|
||||||
|
dst.nc.SetWriteDeadline(time.Now().Add(s.WriteTimeout))
|
||||||
|
}
|
||||||
err = s.sendPacket(dst.bw, &dst.info, c.key, contents)
|
err = s.sendPacket(dst.bw, &dst.info, c.key, contents)
|
||||||
dst.mu.Unlock()
|
dst.mu.Unlock()
|
||||||
|
|
||||||
|
@ -527,6 +534,9 @@ func (c *sclient) keepAliveLoop(ctx context.Context) error {
|
||||||
c.keepAliveTimer.Reset(keepAlive + jitter)
|
c.keepAliveTimer.Reset(keepAlive + jitter)
|
||||||
case <-c.keepAliveTimer.C:
|
case <-c.keepAliveTimer.C:
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
|
if c.s.WriteTimeout != 0 {
|
||||||
|
c.nc.SetWriteDeadline(time.Now().Add(c.s.WriteTimeout))
|
||||||
|
}
|
||||||
err := writeFrame(c.bw, frameKeepAlive, nil)
|
err := writeFrame(c.bw, frameKeepAlive, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = c.bw.Flush()
|
err = c.bw.Flush()
|
||||||
|
|
Loading…
Reference in New Issue