From 8a9e6c87ae50fe259ec82c5f43146b1f8f387fe3 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sat, 26 Feb 2022 21:44:37 -0800 Subject: [PATCH] Set read deadline to handle abandoned allocations Giving it 30s deadline for allocation requests. --- AUTHORS.txt | 1 + internal/allocation/allocation.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index ed79eeb6..619c2adf 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -10,6 +10,7 @@ Atsushi Watanabe backkem cnderrauber David Colburn +David Zhao Herman Banken Hugo Arregui Igor German diff --git a/internal/allocation/allocation.go b/internal/allocation/allocation.go index ac696ec4..644a2da1 100644 --- a/internal/allocation/allocation.go +++ b/internal/allocation/allocation.go @@ -13,6 +13,10 @@ import ( "github.com/pion/turn/v2/internal/proto" ) +const ( + allocationDeadline = 30 * time.Second +) + type allocationResponse struct { transactionID [stun.TransactionIDSize]byte responseAttrs []stun.Setter @@ -245,6 +249,7 @@ func (a *Allocation) packetHandler(m *Manager) { buffer := make([]byte, rtpMTU) for { + _ = a.RelaySocket.SetReadDeadline(time.Now().Add(allocationDeadline)) n, srcAddr, err := a.RelaySocket.ReadFrom(buffer) if err != nil { m.DeleteAllocation(a.fiveTuple)