Skip to content

Commit

Permalink
Set 1 minute timeout for dialing masquerade, 10 second timeout for di…
Browse files Browse the repository at this point in the history
…aling masquerade for vetting
  • Loading branch information
oxtoacart committed May 31, 2023
1 parent 04f7265 commit 4136802
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ func (d *direct) vetOne() {
unvettedMasquerades = append(unvettedMasquerades, m)
}
}
conn, m, masqueradeGood, err := d.dialWith(context.Background(), unvettedMasquerades)

// Don't take more than 10 seconds to dial a masquerade for vetting
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

conn, m, masqueradeGood, err := d.dialWith(ctx, unvettedMasquerades)
if err != nil {
log.Errorf("unexpected error vetting masquerades: %v", err)
return
}
defer conn.Close()

Expand Down Expand Up @@ -330,6 +336,10 @@ func (d *direct) dial(ctx context.Context) (net.Conn, *masquerade, func(bool) bo
}

func (d *direct) dialWith(ctx context.Context, masquerades sortedMasquerades) (net.Conn, *masquerade, func(bool) bool, error) {
// never take more than a minute to dial out
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

for {
masqueradesToTry := masquerades.sortedCopy()
for _, m := range masqueradesToTry {
Expand Down

0 comments on commit 4136802

Please sign in to comment.