Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve race condition on play subcommand #57

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -188,6 +189,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
Loading