Skip to content

Commit

Permalink
http3: rename Server.CloseGracefully to Shutdown (#4701)
Browse files Browse the repository at this point in the history
This is more consistent with standard library naming for graceful
shutdown methods for HTTP/1 and HTTP/2.
  • Loading branch information
marten-seemann authored Oct 15, 2024
1 parent 4a9a81c commit 6af2b1a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions http3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,10 @@ func (s *Server) Close() error {
return err
}

// CloseGracefully shuts down the server gracefully.
// Shutdown shuts down the server gracefully.
// The server sends a GOAWAY frame first, then or for all running requests to complete.
// CloseGracefully in combination with ListenAndServe() (instead of Serve()) may race if it is called before a UDP socket is established.
func (s *Server) CloseGracefully(ctx context.Context) error {
// Shutdown in combination with ListenAndServe() (instead of Serve()) may race if it is called before a UDP socket is established.
func (s *Server) Shutdown(ctx context.Context) error {
s.mutex.Lock()
s.closed = true
// server is never used
Expand Down
2 changes: 1 addition & 1 deletion http3/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ var _ = Describe("Server", func() {
})

It("closes gracefully", func() {
Expect(s.CloseGracefully(context.Background())).To(Succeed())
Expect(s.Shutdown(context.Background())).To(Succeed())
})

It("errors when listening fails", func() {
Expand Down
8 changes: 4 additions & 4 deletions integrationtests/self/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ var _ = Describe("HTTP tests", func() {
go func() {
defer GinkgoRecover()
defer close(done)
Expect(server.CloseGracefully(context.Background())).To(Succeed())
Expect(server.Shutdown(context.Background())).To(Succeed())
fmt.Println("close gracefully done")
}()
time.Sleep(delay)
Expand All @@ -1112,7 +1112,7 @@ var _ = Describe("HTTP tests", func() {
// manually close the client, since we don't support
client.Transport.(*http3.Transport).Close()

// make sure that CloseGracefully returned
// make sure that Shutdown returned
Eventually(done).Should(BeClosed())
})

Expand All @@ -1130,7 +1130,7 @@ var _ = Describe("HTTP tests", func() {
ctx, cancel := context.WithTimeout(context.Background(), delay)
defer cancel()
defer close(shutdownDone)
Expect(server.CloseGracefully(ctx)).To(MatchError(context.DeadlineExceeded))
Expect(server.Shutdown(ctx)).To(MatchError(context.DeadlineExceeded))
}()
for t := range time.NewTicker(delay / 10).C {
if _, err := w.Write([]byte(t.String())); err != nil {
Expand All @@ -1155,7 +1155,7 @@ var _ = Describe("HTTP tests", func() {
Eventually(requestChan).Should(Receive(&requestDuration))
Expect(requestDuration).To(BeNumerically("~", delay, delay/2))

// make sure that CloseGracefully returned
// make sure that Shutdown returned
Eventually(shutdownDone).Should(BeClosed())
})
})

0 comments on commit 6af2b1a

Please sign in to comment.