Skip to content

Commit

Permalink
Fix deadlock
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed Feb 26, 2020
1 parent 4a1c32a commit fd4a1f9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/server/xtreamHandles.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ var xtreamM3uCacheLock = sync.RWMutex{}

func (c *Config) cacheXtreamM3u(m3uURL *url.URL) error {
xtreamM3uCacheLock.Lock()
defer xtreamM3uCacheLock.Unlock()

playlist, err := m3u.Parse(m3uURL.String())
if err != nil {
return err
}

tmp := c.playlist
c.playlist = &playlist
tmp := *c
tmp.playlist = &playlist

path := filepath.Join("/tmp", uuid.NewV4().String()+".iptv-proxy")
f, err := os.Create(path)
Expand All @@ -49,12 +51,10 @@ func (c *Config) cacheXtreamM3u(m3uURL *url.URL) error {
}
defer f.Close()

if err := c.marshallInto(f, true); err != nil {
if err := tmp.marshallInto(f, true); err != nil {
return err
}
xtreamM3uCache[m3uURL.String()] = cacheMeta{path, time.Now()}
c.playlist = tmp
xtreamM3uCacheLock.Unlock()

return nil
}
Expand Down Expand Up @@ -172,6 +172,7 @@ func (c *Config) xtreamXMLTV(ctx *gin.Context) {
}

resp, err := client.GetXMLTV()
client.GetVideoOnDemandCategories()
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
return
Expand Down Expand Up @@ -229,6 +230,7 @@ func (c *Config) hlsrStream(ctx *gin.Context) {
url, ok := hlsChannelsRedirectURL[ctx.Param("channel")+".m3u8"]
if !ok {
ctx.AbortWithError(http.StatusNotFound, errors.New("HSL redirect url not found"))
hlsChannelsRedirectURLLock.RUnlock()
return
}
hlsChannelsRedirectURLLock.RUnlock()
Expand Down

0 comments on commit fd4a1f9

Please sign in to comment.