Skip to content

Commit

Permalink
Fixed double mutex acquisition deadlock when recreating UDP session
Browse files Browse the repository at this point in the history
minor: Opportunistically clean-up stale route rule in outline-cli
closes Jigsaw-Code#342
  • Loading branch information
alamar committed Feb 11, 2025
1 parent efa8083 commit f84ed8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion network/lwip2transport/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ func (h *udpHandler) ReceiveTo(tunConn lwip.UDPConn, data []byte, destAddr *net.

h.mu.Lock()
reqSender, ok := h.senders[laddr]
h.mu.Unlock()
if !ok {
if reqSender, err = h.newSession(tunConn); err != nil {
return
}
h.mu.Lock()
h.senders[laddr] = reqSender
h.mu.Unlock()
}
h.mu.Unlock()

_, err = reqSender.WriteTo(data, destAddr.AddrPort())
return
Expand Down
2 changes: 2 additions & 0 deletions x/examples/outline-cli/routing_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func setupIpRule(svrIp string, routingTable, routingPriority int) error {
ipRule.Invert = true

if err := netlink.RuleAdd(ipRule); err != nil {
// assuming duplicate from previous run, just to make sure it does not stays stale forever in the routing table

This comment has been minimized.

Copy link
@alamar

alamar Feb 11, 2025

Author Owner

This is purely lifestyle fix. When debugging outline-cli, it is possible to shutdown the process immediately - that will lead to retaining this rule in routing table. It will not interfere with networking but it will prevent outline from running until reboot, which is annoying.

Now if there is a stale rule, it will fail to run once, when it will report an error but remove the offending rule. Then on the next run it will work without problems.

defer cleanUpRule()
return fmt.Errorf("failed to add IP rule (table %v, dst %v): %w", ipRule.Table, ipRule.Dst, err)
}
logging.Info.Printf("ip rule 'from all not to %v via table %v' created\n", ipRule.Dst, ipRule.Table)
Expand Down

0 comments on commit f84ed8b

Please sign in to comment.