fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

rpc: do not set timeout if MaxWallTime is specified

Sourcegraph always sets MaxWallTime, so we should let Zoekt respect
that. The MaxWallTime can be greater than 10s, leading to Zoekt
returning at 10s instead of MaxWallTime.

We now only set a timeout on ctx if MaxWallTime is unset (to protect
against accidently not setting in the future). Additionally we update
the default timeout to 20s (same as Sourcegraph).

Change-Id: I42c4968b58482cc3df8d22337a8443b0aec927c9

+12 -3
+12 -3
rpc/internal/srv/srv.go
··· 8 8 "github.com/google/zoekt/query" 9 9 ) 10 10 11 + // defaultTimeout is the maximum amount of time a search request should 12 + // take. This is the same default used by Sourcegraph. 13 + const defaultTimeout = 20 * time.Second 14 + 11 15 type SearchArgs struct { 12 16 Q query.Q 13 17 Opts *zoekt.SearchOptions ··· 30 34 } 31 35 32 36 func (s *Searcher) Search(ctx context.Context, args *SearchArgs, reply *SearchReply) error { 33 - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) 34 - defer cancel() 37 + // Set a timeout if the user hasn't specified one. 38 + if args.Opts != nil && args.Opts.MaxWallTime == 0 { 39 + var cancel context.CancelFunc 40 + ctx, cancel = context.WithTimeout(ctx, defaultTimeout) 41 + defer cancel() 42 + } 43 + 35 44 r, err := s.Searcher.Search(ctx, args.Q, args.Opts) 36 45 if err != nil { 37 46 return err ··· 41 50 } 42 51 43 52 func (s *Searcher) List(ctx context.Context, args *ListArgs, reply *ListReply) error { 44 - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) 53 + ctx, cancel := context.WithTimeout(ctx, defaultTimeout) 45 54 defer cancel() 46 55 r, err := s.Searcher.List(ctx, args.Q) 47 56 if err != nil {