Skip to content

Commit 0c57c7a

Browse files
committed
feat: exit zeroconf server cleanly on close
1 parent e77e438 commit 0c57c7a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

zeroconf/zeroconf.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Zeroconf struct {
2727

2828
listener net.Listener
2929
registrar ServiceRegistrar
30+
closed bool
3031

3132
dh *dh.DiffieHellman
3233

@@ -116,6 +117,11 @@ func (z *Zeroconf) SetCurrentUser(username string) {
116117
// Close stops the zeroconf responder and HTTP listener,
117118
// but does not close the last opened session.
118119
func (z *Zeroconf) Close() {
120+
if z.closed {
121+
return
122+
}
123+
124+
z.closed = true
119125
z.registrar.Shutdown()
120126
_ = z.listener.Close()
121127
}
@@ -307,6 +313,10 @@ func (z *Zeroconf) Serve(handler HandleNewRequestFunc) error {
307313
for {
308314
select {
309315
case err := <-serveErr:
316+
if z.closed {
317+
return nil
318+
}
319+
310320
return err
311321
case req := <-z.reqsChan:
312322
req.result <- handler(req)

0 commit comments

Comments
 (0)