File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
xds/internal/xdsclient/transport Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ func (t *Transport) lrsStartStream() {
6262
6363 ctx , cancel := context .WithCancel (context .Background ())
6464 t .lrsCancelStream = cancel
65+
66+ // Create a new done channel everytime a new stream is created. This ensures
67+ // that we don't close the same channel multiple times (from lrsRunner()
68+ // goroutine) when multiple streams are created and closed.
69+ t .lrsRunnerDoneCh = make (chan struct {})
6570 go t .lrsRunner (ctx )
6671}
6772
@@ -78,6 +83,9 @@ func (t *Transport) lrsStopStream() {
7883
7984 t .lrsCancelStream ()
8085 t .logger .Infof ("Stopping LRS stream" )
86+
87+ // Wait for the runner goroutine to exit. The done channel will be
88+ // recreated when a new stream is created.
8189 <- t .lrsRunnerDoneCh
8290}
8391
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ func (s) TestReportLoad(t *testing.T) {
5454 NodeProto : nodeProto ,
5555 }
5656
57- // Create a transport to the fake server.
57+ // Create a transport to the fake management server.
5858 tr , err := transport .New (transport.Options {
5959 ServerCfg : serverCfg ,
6060 UpdateHandler : func (transport.ResourceUpdate ) error { return nil }, // No ADS validation.
@@ -190,4 +190,16 @@ func (s) TestReportLoad(t *testing.T) {
190190 if _ , err := mgmtServer .LRSStreamCloseChan .Receive (ctx ); err != nil {
191191 t .Fatal ("Timeout waiting for LRS stream to close" )
192192 }
193+
194+ // Calling the load reporting API again should result in the creation of a
195+ // new LRS stream. This ensures that creating and closing multiple streams
196+ // works smoothly.
197+ _ , cancelLRS3 := tr .ReportLoad ()
198+ if err != nil {
199+ t .Fatalf ("Failed to start LRS load reporting: %v" , err )
200+ }
201+ if _ , err := mgmtServer .LRSStreamOpenChan .Receive (ctx ); err != nil {
202+ t .Fatalf ("Timeout when waiting for LRS stream to be created: %v" , err )
203+ }
204+ cancelLRS3 ()
193205}
Original file line number Diff line number Diff line change @@ -202,7 +202,6 @@ func New(opts Options) (*Transport, error) {
202202 versions : make (map [string ]string ),
203203 nonces : make (map [string ]string ),
204204 adsRunnerDoneCh : make (chan struct {}),
205- lrsRunnerDoneCh : make (chan struct {}),
206205 }
207206
208207 // This context is used for sending and receiving RPC requests and
You can’t perform that action at this time.
0 commit comments