Skip to content

Commit

Permalink
fix: improve race condition on play subcommand (#57)
Browse files Browse the repository at this point in the history
* add short sleep
* add TODO
  • Loading branch information
xx4h authored Oct 17, 2024
1 parent db1613a commit 52a6673
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/hctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"os"
"strconv"
"time"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -212,6 +213,13 @@ func (h *Hctl) PlayMusic(obj string, mediaURL string) {

o.PrintSuccessAction(obj, state)
log.Debug().Caller().Msgf("Result: %s(%s) to %s", obj, sub, state)
// TODO: find better way to ensure we don't close the server before file has been served
// -> RaceCondition
// Problem: We could wait for initial connection (e.g. from media player) and only then
// move on to WaitAndClose, but media player is not always (i !guess! it depends on time
// between plays and filesize) re-requesting the file when we play one and the same media
// twice in a short period of time
time.Sleep(100 * time.Millisecond)
s.WaitAndClose()
}
}
Expand Down

0 comments on commit 52a6673

Please sign in to comment.