Skip to content

Commit 2c7acb3

Browse files
committed
Remove dependency graceful
The method `Server.Shutdown` from the `net/http` standard library ought to handle server shutdown gracefully. https://pkg.go.dev/net/http#Server.Shutdown Closes #4594
1 parent 0532e93 commit 2c7acb3

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

clients/client-shell/cmds/signin/signin.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
package signin
33

44
import (
5+
"context"
56
"fmt"
67
"io/ioutil"
78
"net"
89
"net/http"
910
"net/url"
1011
"os"
1112
"strings"
12-
"time"
1313

1414
"github.com/pkg/browser"
1515
"github.com/spf13/cobra"
@@ -19,7 +19,6 @@ import (
1919
"github.com/taskcluster/taskcluster/v44/clients/client-go/tcauth"
2020
"github.com/taskcluster/taskcluster/v44/clients/client-shell/cmds/root"
2121
"github.com/taskcluster/taskcluster/v44/clients/client-shell/config"
22-
graceful "gopkg.in/tylerb/graceful.v1"
2322
)
2423

2524
var log = root.Logger
@@ -66,14 +65,11 @@ func cmdSignin(cmd *cobra.Command, _ []string) error {
6665
// Find port, choose 0 meaning random port, if none
6766
port, _ := cmd.Flags().GetInt("port")
6867

69-
// Setup server that we can shutdown gracefully
70-
s := graceful.Server{
71-
Timeout: 5 * time.Second,
72-
Server: &http.Server{},
73-
}
68+
// Set up server for the redirect page after a successful sign in
69+
s := http.Server{}
7470

7571
// Handle callback
76-
s.Server.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
72+
s.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7773
qs := r.URL.Query()
7874
csh, _ := cmd.Flags().GetBool("csh")
7975
rootURL := config.RootURL()
@@ -101,7 +97,9 @@ func cmdSignin(cmd *cobra.Command, _ []string) error {
10197
</body>
10298
</html>
10399
`))
104-
s.Stop(50 * time.Millisecond)
100+
if err := s.Shutdown(context.Background()); err != nil {
101+
log.Errorf("Error shutting down server: %s\n", err)
102+
}
105103
})
106104

107105
// Start listening on localhost

0 commit comments

Comments
 (0)