Skip to content

Commit

Permalink
server: Add timeouts & improve errors for detection webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
jailuthra committed Jun 9, 2021
1 parent b3de595 commit 761f2aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions server/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io/ioutil"
"math"
"math/big"
"net/http"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -569,15 +568,20 @@ func transcodeSegment(cxn *rtmpConnection, seg *stream.HLSSegment, name string,
glog.Errorf("Unable to marshal detection result into JSON manifestID=%v seqNo=%v", mid, seqNo)
return
}
resp, err := http.Post(DetectionWebhookURL, "application/json", bytes.NewBuffer(jsonValue))
resp, err := DetectionWhClient.Post(DetectionWebhookURL, "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
glog.Errorf("Unable to POST detection result on webhook url=%v manifestID=%v seqNo=%v",
DetectionWebhookURL, mid, seqNo)
glog.Errorf("Unable to POST detection result on webhook url=%v manifestID=%v seqNo=%v, err=%v",
DetectionWebhookURL, mid, seqNo, err)
} else if resp.StatusCode != 200 {
rbody, _ := ioutil.ReadAll(resp.Body)
rbody, rerr := ioutil.ReadAll(resp.Body)
resp.Body.Close()
glog.Errorf("Detection webhook returned error status=%v err=%v manifestID=%v seqNo=%v",
resp.StatusCode, string(rbody), mid, seqNo)
if rerr != nil {
glog.Errorf("Detection webhook returned error status=%v manifestID=%v seqNo=%v with unreadable body err=%v",
resp.StatusCode, mid, seqNo, rerr)
} else {
glog.Errorf("Detection webhook returned error status=%v err=%v manifestID=%v seqNo=%v",
resp.StatusCode, string(rbody), mid, seqNo)
}
}
}(cxn.mid, seg.SeqNo, res.Detections)
}
Expand Down
1 change: 1 addition & 0 deletions server/mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var BroadcastJobVideoProfiles = []ffmpeg.VideoProfile{ffmpeg.P240p30fps4x3, ffmp

var AuthWebhookURL string
var DetectionWebhookURL string
var DetectionWhClient = &http.Client{Timeout: 2 * time.Second}

// For HTTP push watchdog
var httpPushTimeout = 1 * time.Minute
Expand Down

0 comments on commit 761f2aa

Please sign in to comment.