[pkgsite] cmd/internal/pkgsite-cli: add timeout flag and handle timeouts gracefully

3 views
Skip to first unread message

Ethan Lee (Gerrit)

unread,
May 9, 2026, 1:16:22 PM (2 days ago) May 9
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ethan Lee has uploaded the change for review

Commit message

cmd/internal/pkgsite-cli: add timeout flag and handle timeouts gracefully
Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5

Change diff

diff --git a/cmd/internal/pkgsite-cli/command.go b/cmd/internal/pkgsite-cli/command.go
index 2955028..4e4b2e2 100644
--- a/cmd/internal/pkgsite-cli/command.go
+++ b/cmd/internal/pkgsite-cli/command.go
@@ -13,6 +13,7 @@
"runtime/debug"
"slices"
"strings"
+ "time"
)

// A command describes a subcommand of the tool.
@@ -161,12 +162,14 @@
jsonOut bool
limit int
server string
+ timeout time.Duration
}

func (f *commonFlags) register(fs *flag.FlagSet) {
fs.BoolVar(&f.jsonOut, "json", false, "output JSON")
fs.IntVar(&f.limit, "limit", 0, "max results (default: 25)")
fs.StringVar(&f.server, "server", defaultServer, "API server URL")
+ fs.DurationVar(&f.timeout, "timeout", 30*time.Second, "request timeout")
}

func (f *commonFlags) effectiveLimit() int {
diff --git a/cmd/internal/pkgsite-cli/main.go b/cmd/internal/pkgsite-cli/main.go
index 3b2854c..73b3006 100644
--- a/cmd/internal/pkgsite-cli/main.go
+++ b/cmd/internal/pkgsite-cli/main.go
@@ -15,7 +15,9 @@
package main

import (
+ "context"
"encoding/json"
+ "errors"
"flag"
"fmt"
"io"
@@ -114,10 +116,18 @@
if !ok {
aerr = &client.Error{Code: 1, Message: err.Error()}
}
+ if errors.Is(err, context.DeadlineExceeded) {
+ aerr.Message = "request timed out"
+ aerr.Fixes = []string{"use the -timeout flag to increase the timeout"}
+ }
writeJSON(stdout, stderr, aerr)
return
}
- fmt.Fprintln(stderr, err)
+ if errors.Is(err, context.DeadlineExceeded) {
+ fmt.Fprintln(stderr, "Error: request timed out; use the -timeout flag to increase it")
+ } else {
+ fmt.Fprintln(stderr, err)
+ }
}

func writeJSON(stdout, stderr io.Writer, v any) int {
diff --git a/cmd/internal/pkgsite-cli/module.go b/cmd/internal/pkgsite-cli/module.go
index e82da40..160d5c5 100644
--- a/cmd/internal/pkgsite-cli/module.go
+++ b/cmd/internal/pkgsite-cli/module.go
@@ -8,7 +8,6 @@
"context"
"flag"
"io"
- "time"

"golang.org/x/pkgsite/cmd/internal/pkgsite-cli/client"
"golang.org/x/sync/errgroup"
@@ -21,7 +20,7 @@
}
path, version := splitPathVersion(args[0])

- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), m.timeout)
defer cancel()

c, err := client.New(m.server)
diff --git a/cmd/internal/pkgsite-cli/package.go b/cmd/internal/pkgsite-cli/package.go
index f49dd91..d5a8b98 100644
--- a/cmd/internal/pkgsite-cli/package.go
+++ b/cmd/internal/pkgsite-cli/package.go
@@ -11,7 +11,6 @@
"io"
"os/exec"
"strings"
- "time"

"golang.org/x/pkgsite/cmd/internal/pkgsite-cli/client"
)
@@ -32,7 +31,7 @@
p.goos = goos
p.goarch = goarch

- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), p.timeout)
defer cancel()

c, err := client.New(p.server)
diff --git a/cmd/internal/pkgsite-cli/search.go b/cmd/internal/pkgsite-cli/search.go
index 56a022b..97b4281 100644
--- a/cmd/internal/pkgsite-cli/search.go
+++ b/cmd/internal/pkgsite-cli/search.go
@@ -9,7 +9,6 @@
"flag"
"io"
"strings"
- "time"

"golang.org/x/pkgsite/cmd/internal/pkgsite-cli/client"
)
@@ -21,7 +20,7 @@
}
query := strings.Join(args, " ")

- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), s.timeout)
defer cancel()

c, err := client.New(s.server)

Change information

Files:
  • M cmd/internal/pkgsite-cli/command.go
  • M cmd/internal/pkgsite-cli/main.go
  • M cmd/internal/pkgsite-cli/module.go
  • M cmd/internal/pkgsite-cli/package.go
  • M cmd/internal/pkgsite-cli/search.go
Change size: S
Delta: 5 files changed, 17 insertions(+), 7 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
Gerrit-Change-Number: 776381
Gerrit-PatchSet: 1
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

kokoro (Gerrit)

unread,
May 9, 2026, 1:45:47 PM (2 days ago) May 9
to Ethan Lee, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Jonathan Amsterdam, golang-co...@googlegroups.com
Attention needed from Ethan Lee and Jonathan Amsterdam

kokoro voted kokoro-CI+1

Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/259e74f5-1081-49cc-829e-507fad0e8ee1

kokoro-CI+1
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
  • Jonathan Amsterdam
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    • requirement satisfiedkokoro-CI-Passes
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pkgsite
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
    Gerrit-Change-Number: 776381
    Gerrit-PatchSet: 2
    Gerrit-Owner: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: kokoro <noreply...@google.com>
    Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
    Gerrit-Attention: Ethan Lee <etha...@google.com>
    Gerrit-Comment-Date: Sat, 09 May 2026 17:45:42 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Jonathan Amsterdam (Gerrit)

    unread,
    May 9, 2026, 5:50:13 PM (2 days ago) May 9
    to Ethan Lee, goph...@pubsubhelper.golang.org, kokoro, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
    Attention needed from Ethan Lee

    Jonathan Amsterdam voted and added 1 comment

    Votes added by Jonathan Amsterdam

    Code-Review+2

    1 comment

    File cmd/internal/pkgsite-cli/main.go
    Line 121, Patchset 2 (Latest): aerr.Fixes = []string{"use the -timeout flag to increase the timeout"}
    Jonathan Amsterdam . unresolved

    a second fix is to reduce the cost of the request, for example by using a smaller limit if applicable

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ethan Lee
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    • requirement satisfiedkokoro-CI-Passes
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pkgsite
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
    Gerrit-Change-Number: 776381
    Gerrit-PatchSet: 2
    Gerrit-Owner: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: kokoro <noreply...@google.com>
    Gerrit-Attention: Ethan Lee <etha...@google.com>
    Gerrit-Comment-Date: Sat, 09 May 2026 21:50:09 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Hyang-Ah Hana Kim (Gerrit)

    unread,
    12:07 PM (11 hours ago) 12:07 PM
    to Ethan Lee, goph...@pubsubhelper.golang.org, Hyang-Ah Hana Kim, Jonathan Amsterdam, kokoro, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
    Attention needed from Ethan Lee

    Hyang-Ah Hana Kim voted Code-Review+2

    Code-Review+2
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ethan Lee
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    • requirement satisfiedkokoro-CI-Passes
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pkgsite
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
    Gerrit-Change-Number: 776381
    Gerrit-PatchSet: 2
    Gerrit-Owner: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: kokoro <noreply...@google.com>
    Gerrit-Attention: Ethan Lee <etha...@google.com>
    Gerrit-Comment-Date: Mon, 11 May 2026 16:06:55 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Ethan Lee (Gerrit)

    unread,
    6:23 PM (5 hours ago) 6:23 PM
    to goph...@pubsubhelper.golang.org, Hyang-Ah Hana Kim, Jonathan Amsterdam, kokoro, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
    Attention needed from Hyang-Ah Hana Kim and Jonathan Amsterdam

    Ethan Lee added 2 comments

    Patchset-level comments
    File-level comment, Patchset 4 (Latest):
    Ethan Lee . resolved

    kokoro rerun

    File cmd/internal/pkgsite-cli/main.go
    Line 121, Patchset 2: aerr.Fixes = []string{"use the -timeout flag to increase the timeout"}
    Jonathan Amsterdam . resolved

    a second fix is to reduce the cost of the request, for example by using a smaller limit if applicable

    Ethan Lee

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Hyang-Ah Hana Kim
    • Jonathan Amsterdam
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    • requirement is not satisfiedkokoro-CI-Passes
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pkgsite
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
    Gerrit-Change-Number: 776381
    Gerrit-PatchSet: 4
    Gerrit-Owner: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: kokoro <noreply...@google.com>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
    Gerrit-Comment-Date: Mon, 11 May 2026 22:22:59 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Jonathan Amsterdam <j...@google.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    kokoro (Gerrit)

    unread,
    6:50 PM (4 hours ago) 6:50 PM
    to Ethan Lee, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Hyang-Ah Hana Kim, Jonathan Amsterdam, golang-co...@googlegroups.com
    Attention needed from Ethan Lee, Hyang-Ah Hana Kim and Jonathan Amsterdam

    kokoro voted kokoro-CI+1

    Kokoro presubmit build finished with status: SUCCESS

    Attention is currently required from:
    • Ethan Lee
    • Hyang-Ah Hana Kim
    • Jonathan Amsterdam
      Submit Requirements:
        • requirement satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement satisfiedReview-Enforcement
        • requirement satisfiedTryBots-Pass
        • requirement satisfiedkokoro-CI-Passes
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: pkgsite
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
        Gerrit-Change-Number: 776381
        Gerrit-PatchSet: 4
        Gerrit-Owner: Ethan Lee <etha...@google.com>
        Gerrit-Reviewer: Ethan Lee <etha...@google.com>
        Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
        Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
        Gerrit-Reviewer: kokoro <noreply...@google.com>
        Gerrit-CC: kokoro <noreply...@google.com>
        Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
        Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
        Gerrit-Attention: Ethan Lee <etha...@google.com>
        Gerrit-Comment-Date: Mon, 11 May 2026 22:50:08 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Gopher Robot (Gerrit)

        unread,
        6:54 PM (4 hours ago) 6:54 PM
        to Ethan Lee, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, kokoro, golang...@luci-project-accounts.iam.gserviceaccount.com, Hyang-Ah Hana Kim, Jonathan Amsterdam, golang-co...@googlegroups.com

        Gopher Robot submitted the change with unreviewed changes

        Unreviewed changes

        2 is the latest approved patch-set.
        The change was submitted with unreviewed changes in the following files:

        ```
        The name of the file: cmd/internal/pkgsite-cli/main.go
        Insertions: 1, Deletions: 1.

        The diff is too large to show. Please review the diff.
        ```

        Change information

        Commit message:
        cmd/internal/pkgsite-cli: add timeout flag and handle timeouts gracefully
        Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
        Files:
        • M cmd/internal/pkgsite-cli/command.go
        • M cmd/internal/pkgsite-cli/main.go
        • M cmd/internal/pkgsite-cli/module.go
        • M cmd/internal/pkgsite-cli/package.go
        • M cmd/internal/pkgsite-cli/search.go
        Change size: S
        Delta: 5 files changed, 17 insertions(+), 7 deletions(-)
        Branch: refs/heads/master
        Submit Requirements:
        Open in Gerrit
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: merged
        Gerrit-Project: pkgsite
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie6a2891c88b241318ab99c6570864b2015e09de5
        Gerrit-Change-Number: 776381
        Gerrit-PatchSet: 5
        Gerrit-Owner: Ethan Lee <etha...@google.com>
        Gerrit-Reviewer: Ethan Lee <etha...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        open
        diffy
        satisfied_requirement
        Reply all
        Reply to author
        Forward
        0 new messages