Skip to content

Commit

Permalink
Set read deadline to handle abandoned allocations
Browse files Browse the repository at this point in the history
Giving it 30s deadline for allocation requests.
  • Loading branch information
davidzhao committed Feb 27, 2022
1 parent dfe04cb commit 8a9e6c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Atsushi Watanabe <atsushi.w@ieee.org>
backkem <mail@backkem.me>
cnderrauber <zengjie9004@gmail.com>
David Colburn <xero73@gmail.com>
David Zhao <david@davidzhao.com>
Herman Banken <hermanbanken@gmail.com>
Hugo Arregui <hugo.arregui@gmail.com>
Igor German <igor.german@synesis.ru>
Expand Down
5 changes: 5 additions & 0 deletions internal/allocation/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8a9e6c8

Please sign in to comment.