From 73068a9c1f6269b10b22bcfa592d9151a0ed9d8e Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Fri, 14 Mar 2025 22:50:50 -0400 Subject: [PATCH] close the server when leaving --- chord/httpnode/server.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/chord/httpnode/server.go b/chord/httpnode/server.go index a1e0a77..060c789 100644 --- a/chord/httpnode/server.go +++ b/chord/httpnode/server.go @@ -11,8 +11,9 @@ import ( "net/http" "net/netip" - "git.sunturtle.xyz/zephyr/chord/chord" "github.com/go-json-experiment/json" + + "git.sunturtle.xyz/zephyr/chord/chord" ) type Node struct { @@ -22,6 +23,9 @@ type Node struct { // TODO(branden): really we should have a client per peer so that we can // interchange protocols client chord.Client + // l is the listener that the HTTP server serves. + // When the server leaves, it closes the listener. + l net.Listener } // New creates an instance of a Chord network that responds on HTTP. @@ -39,6 +43,7 @@ func New(l net.Listener, cl chord.Client, self *chord.Node) (*Node, error) { r := &Node{ self: self, client: cl, + l: l, } return r, nil } @@ -165,4 +170,6 @@ func (n *Node) bye(w http.ResponseWriter, r *http.Request) { } n.self.Leave(p, s) w.WriteHeader(http.StatusNoContent) + // Close the listener so that the server will shut down. + n.l.Close() }