From 4136802151da5e815765153dfebb3e9b882e73ba Mon Sep 17 00:00:00 2001 From: Ox Cart Date: Wed, 31 May 2023 14:26:58 -0500 Subject: [PATCH] Set 1 minute timeout for dialing masquerade, 10 second timeout for dialing masquerade for vetting --- direct.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/direct.go b/direct.go index c3f4352..4bf9afe 100644 --- a/direct.go +++ b/direct.go @@ -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() @@ -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 {