summaryrefslogtreecommitdiff
path: root/recording
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-07-29 19:14:17 +0800
committerKeuin <[email protected]>2023-07-29 20:16:45 +0800
commita153bf02d1cf05f020d263e9670a76ae99cfeb02 (patch)
tree4ad7c12b81e6e37764230bc499a5d3f090766aba /recording
parentcca3c828e0a12ab31ee928a82e672082be642d01 (diff)
Bugfix: heartbeat packets are sent irregularly when idle, causing EOF errors
Diffstat (limited to 'recording')
-rw-r--r--recording/watcher.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/recording/watcher.go b/recording/watcher.go
index f06b405..515def1 100644
--- a/recording/watcher.go
+++ b/recording/watcher.go
@@ -70,7 +70,13 @@ func watch(
// the danmaku server requires heartbeat messages every 30 seconds
heartbeat := func() error {
+ logger.Debug("Sending heartbeat...")
err := dm.Heartbeat()
+ if err == nil {
+ logger.Info("Heartbeat sent OK.")
+ } else {
+ logger.Error("Failed to send heartbeat: %v", err)
+ }
return err
}
@@ -96,15 +102,27 @@ func watch(
logger.Info("The live is not started yet. Waiting...")
}
+ hbCtx, hbCancel := context.WithCancel(ctx)
+ defer hbCancel()
+ go func() {
+ for {
+ select {
+ case <-heartBeatTimer.C:
+ err = heartbeat()
+ if err != nil {
+ logger.Error("heartbeat failed: %v", err)
+ }
+ case <-hbCtx.Done():
+ logger.Debug("Heartbeat loop is stopped.")
+ return
+ }
+ }
+ }()
+
for {
select {
case <-ctx.Done():
return ctx.Err()
- case <-heartBeatTimer.C:
- err = heartbeat()
- if err != nil {
- return errs.NewError(errs.Heartbeat, err)
- }
default:
var msg dmpkg.DanmakuExchange
msg, err = dm.ReadExchange()