Skip to content

Commit

Permalink
Bugfix terminating streams and possible fix for counter error, unkill…
Browse files Browse the repository at this point in the history
…ed processes and RAM eating
  • Loading branch information
marcelGoerentz committed Nov 7, 2024
1 parent 4bdc5bc commit 8720e1c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ RUN apk update && apk upgrade && apk add ca-certificates curl ffmpeg vlc doas tz
RUN echo "permit persist :wheel" >> /etc/doas.d/doas.conf

# Add threadfin group and user
RUN addgroup -S threadfin -g ${THREADFIN_GID} \
&& adduser threadfin -G threadfin -u ${THREADFIN_UID} -g ${THREADFIN_GID} -s /bin/sh -D \
RUN addgroup -S threadfin -g "${THREADFIN_GID}" \
&& adduser threadfin -G threadfin -u "${THREADFIN_UID}" -g "${THREADFIN_GID}" -s /bin/sh -D \
&&adduser threadfin wheel \
&& echo "threadfin:threadfin" | chpasswd

Expand All @@ -86,9 +86,6 @@ RUN chmod +rx $THREADFIN_BIN/threadfin && mkdir $THREADFIN_HOME/cache
# Create working directories for Threadfin
RUN mkdir $THREADFIN_CONF && chmod a+rwX $THREADFIN_CONF && mkdir $THREADFIN_TEMP && chmod a+rwX $THREADFIN_TEMP

# Add threadfin group and user
RUN addgroup -S threadfin -g ${THREADFIN_GID} && adduser -S threadfin -G threadfin -u ${THREADFIN_UID} -g ${THREADFIN_GID} -s /bin/sh

# Configure container volume mappings
VOLUME $THREADFIN_CONF
VOLUME $THREADFIN_TEMP
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module threadfin
go 1.22

require (
github.com/avfs/avfs v0.33.0
github.com/avfs/avfs v0.34.0
github.com/gorilla/websocket v1.5.3
github.com/hashicorp/go-version v1.7.0
github.com/koron/go-ssdp v0.0.4
golang.org/x/text v0.18.0
golang.org/x/text v0.19.0
)

require (
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
)
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/avfs/avfs v0.33.0 h1:5WQXbUbr6VS7aani39ZN2Vrd/s3wLnyih1Sc4ExWTxs=
github.com/avfs/avfs v0.33.0/go.mod h1:Q59flcFRYe9KYkNMfrLUJney3yeKGQpcWRyxsDBW7vI=
github.com/avfs/avfs v0.34.0 h1:1smP9udOqkYM0PyTb44vZZwzrrMaNQOxNL18kZ7f5L4=
github.com/avfs/avfs v0.34.0/go.mod h1:LnzrUO5acMU5NCkohHcUN15YrnkxiJ/lRLQOZSp39ow=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
Expand All @@ -8,7 +8,11 @@ github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0=
github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
28 changes: 12 additions & 16 deletions src/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,6 @@ func bufferingStream(streamInfo StreamInfo, w http.ResponseWriter, r *http.Reque
killClientConnection(streamID, playlist.PlaylistID, false)
return
}

file.Close()
killClientConnection(streamID, playlist.PlaylistID, false)
return
}

file.Close()
Expand Down Expand Up @@ -786,18 +782,18 @@ func thirdPartyBuffer(streamID int, playlistID string, useBackup bool, backupNum

// Byte-Daten vom Prozess
stdOut, err := cmd.StdoutPipe()
if err != nil {
if err != nil && err != io.EOF {
ShowError(err, 0)
terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)
addErrorToStream(err)
return
}

// Log-Daten vom Prozess
logOut, err := cmd.StderrPipe()
if err != nil {
if err != nil && err != io.EOF {
ShowError(err, 0)
terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)
addErrorToStream(err)
return
}
Expand Down Expand Up @@ -868,7 +864,7 @@ func thirdPartyBuffer(streamID int, playlistID string, useBackup bool, backupNum
select {
case timeout := <-t:
if timeout >= 20 && tmpSegment == 1 {
terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)
err = errors.New("Timeout")
ShowError(err, 4006)
addErrorToStream(err)
Expand All @@ -885,20 +881,21 @@ func thirdPartyBuffer(streamID int, playlistID string, useBackup bool, backupNum
}

if !clientConnection(stream) {
terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)
f.Close()
return
}

n, err := reader.Read(buffer)
if err == io.EOF {
terminateProcessGracefully(cmd, stream)
break
}

fileSize = fileSize + len(buffer[:n])

if _, err := f.Write(buffer[:n]); err != nil {
terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)
ShowError(err, 0)
addErrorToStream(err)
return
Expand Down Expand Up @@ -931,7 +928,7 @@ func thirdPartyBuffer(streamID int, playlistID string, useBackup bool, backupNum
_, errCreate = bufferVFS.Create(tmpFile)
f, errOpen = bufferVFS.OpenFile(tmpFile, os.O_APPEND|os.O_WRONLY, 0600)
if errCreate != nil || errOpen != nil {
terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)
ShowError(err, 0)
addErrorToStream(err)
return
Expand All @@ -941,16 +938,14 @@ func thirdPartyBuffer(streamID int, playlistID string, useBackup bool, backupNum

}

terminateProcessGracefully(cmd)
terminateProcessGracefully(cmd, stream)

err = errors.New(bufferType + " error")

addErrorToStream(err)
ShowError(err, 1204)

time.Sleep(time.Duration(500) * time.Millisecond)
clientConnection(stream)

return
}
}
Expand Down Expand Up @@ -987,11 +982,12 @@ func initBufferVFS(virtual bool) {

}

func terminateProcessGracefully(cmd *exec.Cmd) {
func terminateProcessGracefully(cmd *exec.Cmd, stream ThisStream) {
if cmd.Process != nil {
cmd.Process.Signal(syscall.SIGKILL)
cmd.Wait()
deletPIDfromDisc(fmt.Sprintf("%d", cmd.Process.Pid))
// clientConnection(stream)
}
}

Expand Down
2 changes: 1 addition & 1 deletion threadfin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var GitHub = GitHubStruct{Branch: "Main", User: "marcelGoerentz", Repo: "Threadf
const Name = "Threadfin"

// Version : Version, die Build Nummer wird in der main func geparst.
const Version = "1.6.1-beta"
const Version = "1.6.2-beta"

// DBVersion : Datanbank Version
const DBVersion = "0.5.0"
Expand Down

0 comments on commit 8720e1c

Please sign in to comment.