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

clean up zombies #686

Merged
merged 4 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions build/egress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
FROM livekit/gstreamer:1.22.8-dev

ARG TARGETPLATFORM
ARG TARGETARCH
ENV TARGETARCH=${TARGETARCH}
ENV TARGETPLATFORM=${TARGETPLATFORM}

WORKDIR /workspace

# install go
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then GOARCH=arm64; else GOARCH=amd64; fi && \
wget https://go.dev/dl/go1.22.1.linux-${GOARCH}.tar.gz && \
RUN wget https://go.dev/dl/go1.22.1.linux-${TARGETARCH}.tar.gz && \
rm -rf /usr/local/go && \
tar -C /usr/local -xzf go1.22.1.linux-${GOARCH}.tar.gz
tar -C /usr/local -xzf go1.22.1.linux-${TARGETARCH}.tar.gz
ENV PATH="/usr/local/go/bin:${PATH}"


# download go modules
COPY go.mod .
COPY go.sum .
Expand All @@ -42,8 +43,13 @@ COPY --from=livekit/egress-templates workspace/build/ cmd/server/templates/
RUN find cmd/server/templates/ -name *.map | xargs rm

# build
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then GOARCH=arm64; else GOARCH=amd64; fi && \
CGO_ENABLED=1 GOOS=linux GOARCH=${GOARCH} GO111MODULE=on GODEBUG=disablethp=1 go build -a -o egress ./cmd/server
RUN CGO_ENABLED=1 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on GODEBUG=disablethp=1 go build -a -o egress ./cmd/server

# install tini
ENV TINI_VERSION v0.19.0

ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
RUN chmod +x /tini

FROM livekit/gstreamer:1.22.8-prod

Expand Down Expand Up @@ -73,8 +79,10 @@ RUN useradd -ms /bin/bash -g root -G sudo,pulse,pulse-access egress
RUN mkdir -p home/egress/tmp home/egress/.cache/xdgr && \
chown -R egress /home/egress


# copy files
COPY --from=0 /workspace/egress /bin/
COPY --from=0 /tini /tini
COPY build/egress/entrypoint.sh /

# run
Expand Down
2 changes: 1 addition & 1 deletion build/egress/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ rm -rf /var/run/pulse /var/lib/pulse /home/egress/.config/pulse /home/egress/.ca
pulseaudio -D --verbose --exit-idle-time=-1 --disallow-exit

# Run egress service
exec egress
exec /tini -- egress
21 changes: 12 additions & 9 deletions pkg/pipeline/source/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const (
)

type WebSource struct {
pulseSink string
xvfb *exec.Cmd
chromeCancel context.CancelFunc
pulseSink string
xvfb *exec.Cmd
closeChrome context.CancelFunc

startRecording chan struct{}
endRecording chan struct{}
Expand Down Expand Up @@ -109,10 +109,10 @@ func (s *WebSource) GetEndedAt() int64 {
}

func (s *WebSource) Close() {
if s.chromeCancel != nil {
if s.closeChrome != nil {
logger.Debugw("closing chrome")
s.chromeCancel()
s.chromeCancel = nil
s.closeChrome()
s.closeChrome = nil
}

if s.xvfb != nil {
Expand Down Expand Up @@ -254,9 +254,12 @@ func (s *WebSource) launchChrome(ctx context.Context, p *config.PipelineConfig,
)
}

allocCtx, _ := chromedp.NewExecAllocator(context.Background(), opts...)
chromeCtx, cancel := chromedp.NewContext(allocCtx)
s.chromeCancel = cancel
allocCtx, allocCancel := chromedp.NewExecAllocator(context.Background(), opts...)
chromeCtx, chromeCancel := chromedp.NewContext(allocCtx)
s.closeChrome = func() {
chromeCancel()
allocCancel()
}

chromedp.ListenTarget(chromeCtx, func(ev interface{}) {
switch ev := ev.(type) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/server_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"os/exec"
"path"
"syscall"
"time"

"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -119,6 +120,7 @@ func (s *Server) launchProcess(req *rpc.StartEgressRequest, info *livekit.Egress
cmd.Dir = "/"
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}

s.monitor.EgressStarted(req)

Expand Down
Loading