Skip to content

Commit 3339c84

Browse files
committed
Close connections on cluster shutdown
1 parent 44190c3 commit 3339c84

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

‎mlp-ea-decentralized/common/ga/cluster.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (c *Cluster) Start(metadata NodeMetadata) {
102102

103103
c.list = list
104104
c.Logger.Infof("Local cluster node: %s", c.list.LocalNode().String())
105+
defer c.list.Shutdown()
105106

106107
// Try to join a cluster with bootstap nodes.
107108
// If it fails, be an standalone node waiting for incoming connections

‎mlp-ea-decentralized/common/ga/cluster_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
func TestCluster(t *testing.T) {
99
recvBestChan := make(chan Individual, 100)
1010

11-
peer1 := MakeCluster(9998, 100, nil, []string{})
12-
peer2 := MakeCluster(9999, 100, recvBestChan, []string{"127.0.0.1:9998"})
11+
peer1 := MakeCluster(6666, 100, nil, []string{})
12+
peer2 := MakeCluster(6667, 100, recvBestChan, []string{"127.0.0.1:6666"})
1313

1414
// Launch First peer and wait for it to be ready
1515
go peer1.Start(NodeMetadata{})

‎mlp-ea-decentralized/common/ga/poolModel.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,14 @@ func (pool *PoolModel) handleEvaluate() {
343343
if err != nil {
344344
Log.Fatalf("Failed to listen: %v", err)
345345
}
346+
defer lisNative.Close()
346347

347348
// Setup listener for wasm clients based on websockets
348349
lisWasm, err := ws.Listen(fmt.Sprintf("ws://%s:%d", listenAddr, wasmPort), nil)
349350
if err != nil {
350351
panic(err)
351352
}
352-
defer lisNative.Close()
353+
defer lisWasm.Close()
353354

354355
Log.Infof("gRPC Listening on %s", lisNative.Addr().String())
355356
go pool.grpcServer.Serve(lisNative)
@@ -360,6 +361,7 @@ func (pool *PoolModel) handleEvaluate() {
360361
// Wait until stop is received
361362
select {
362363
case <-pool.stop:
364+
return
363365
}
364366
}
365367

0 commit comments

Comments
 (0)