Skip to content

Commit

Permalink
Dji Tello Halt does not terminate all the related goroutines and may …
Browse files Browse the repository at this point in the history
…wait forever when it is called multiple times

Halt method waits forever when at least one of the goroutines is blocked by its Read method. To avoid this, I make Halt method close the connections before writing to doneCh.
  • Loading branch information
st-user authored and deadprogram committed Sep 26, 2022
1 parent 11259d4 commit 7031d1e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions platforms/dji/tello/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,23 @@ func (d *Driver) Start() error {
// Halt stops the driver.
func (d *Driver) Halt() (err error) {
// send a landing command when we disconnect, and give it 500ms to be received before we shutdown
d.Land()
readerCount := atomic.LoadInt32(&d.doneChReaderCount)
for i := 0; i < int(readerCount); i++ {
d.doneCh <- struct{}{}
if d.cmdConn != nil {
d.Land()
}

time.Sleep(500 * time.Millisecond)

d.cmdConn.Close()
if d.cmdConn != nil {
d.cmdConn.Close()
}

if d.videoConn != nil {
d.videoConn.Close()
}
readerCount := atomic.LoadInt32(&d.doneChReaderCount)
for i := 0; i < int(readerCount); i++ {
d.doneCh <- struct{}{}
}

return
}

Expand Down

0 comments on commit 7031d1e

Please sign in to comment.