Skip to content

Commit

Permalink
Make sure to close the listening socket when context is exhausted
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
  • Loading branch information
mudler committed Aug 16, 2024
1 parent 50aa8e9 commit c3f874b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/p2p/federated_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func (fs *FederatedServer) proxy(ctx context.Context, node *node.Node) error {
return err
}
// ll.Info("Binding local port on", srcaddr)

go func() {
<-ctx.Done()
l.Close()
}()
ledger, _ := node.Ledger()

// Announce ourselves so nodes accepts our connection
Expand Down
5 changes: 5 additions & 0 deletions core/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func allocateLocalService(ctx context.Context, node *node.Node, listenAddr, serv
zlog.Error().Err(err).Msg("Error listening")
return err
}
go func() {
<-ctx.Done()
l.Close()
}()

// ll.Info("Binding local port on", srcaddr)

ledger, _ := node.Ledger()
Expand Down

0 comments on commit c3f874b

Please sign in to comment.