Skip to content

Commit

Permalink
when node is closing, avoid creating new port or new connections
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Sep 21, 2023
1 parent f81129b commit 7289f74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion channel_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import (
type channelProvider struct {
n *Node
eca endpointChannelProvider

terminate chan struct{}
}

func newChannelProvider(n *Node, eca endpointChannelProvider) (*channelProvider, error) {
return &channelProvider{
n: n,
eca: eca,
terminate: make(chan struct{}),
}, nil
}

func (cp *channelProvider) close() {
close(cp.terminate)
cp.eca.close()
}

Expand Down Expand Up @@ -49,7 +53,8 @@ func (cp *channelProvider) run() {
// before creating another channel
select {
case <-ch.done:
case <-cp.n.terminate:
case <-cp.terminate:
return
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions endpoint_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ var _ endpointChannelProvider = (*endpointSerial)(nil)

func TestEndpointSerial(t *testing.T) {
done := make(chan struct{})
first := false
n := 0

serialOpenFunc = func(name string, baud int) (io.ReadWriteCloser, error) {
remote, local := newDummyReadWriterPair()

// skip first call to serialOpenFunc()
if !first {
first = true
n++
switch n {
case 1:
return remote, nil

case 2:

default:
t.Errorf("should not happen")
}

go func() {
Expand Down

0 comments on commit 7289f74

Please sign in to comment.