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

[Bug]: Chromium Headless Shell Goes into Zombie Mode #521

Open
nitheeshc opened this issue Jan 23, 2025 · 1 comment
Open

[Bug]: Chromium Headless Shell Goes into Zombie Mode #521

nitheeshc opened this issue Jan 23, 2025 · 1 comment
Labels
p2-bug Something isn't working

Comments

@nitheeshc
Copy link

  • playwright-go Version: v0.4901.0
  • Browser: chromium headless
  • OS and version: debian bookworm

Bug description
I am using playwright golang library to do some automation tasks, I run my golang program in a debian bookworm/trixie container

When i use chromium headless browser, as soon as i close the browser & stop the playwright instance, the headless shell that was invoked goes into zombie mode. This is also causing the container to gradually increase its memory consumption, even though the golang memory consumption(RSS) remains constant.

Attaching the Dockerfile, go.mod, main.go & also some info of the process which are in zombie mode
To Reproduce

  • Program Code
package main

import (
	"github.com/playwright-community/playwright-go"
	"github.com/rs/zerolog/log"
	"time"
)

func main() {
	for {
		pw, err := playwright.Run()

		if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to start Playwright Instance")
		}
	
		browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: playwright.Bool(true)})
		if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to launch browser")
		}
	
		page, err := browser.NewPage()
		if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to create page")
		}
	
		_, err = page.Goto("https://playwright.dev")
		if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to goto page")
		}
		log.Info().Msg("Sleeping for 2 seconds")
		time.Sleep(2 * time.Second)
	
		err = page.Close(); if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to close page")
		}
	
		err = browser.Close(); if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to close browser")
		}
	
		err = pw.Stop(); if err != nil {
			log.Error().Stack().Err(err).Msg("Failed to stop Playwright Instance")
		}

		log.Info().Msg("Sleeping for 10 seconds")
		time.Sleep(5 * time.Second)
	}
}
  • go.mod
module playwright

go 1.23.3

require (
	github.com/playwright-community/playwright-go v0.4901.0
	github.com/rs/zerolog v1.33.0
)

require (
	github.com/deckarep/golang-set/v2 v2.6.0 // indirect
	github.com/go-jose/go-jose/v3 v3.0.3 // indirect
	github.com/go-stack/stack v1.8.1 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.19 // indirect
	golang.org/x/sys v0.17.0 // indirect
)
  • Dockerfile
FROM --platform=$BUILDPLATFORM golang:1.23.3 AS build
WORKDIR /src

RUN --mount=type=cache,target=/go/pkg/mod/ \
    --mount=type=bind,source=go.sum,target=go.sum \
    --mount=type=bind,source=go.mod,target=go.mod \
    go mod download -x

RUN go install github.com/playwright-community/playwright-go/cmd/playwright@latest && \
    PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
    playwright install --only-shell --with-deps chromium

ARG TARGETARCH

RUN --mount=type=cache,target=/go/pkg/mod/ \
    --mount=type=bind,target=. \
    CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/test

FROM debian:trixie-slim AS final

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

RUN apt-get update && \
    apt-get install -y ca-certificates htop procps && \
    rm -rf  /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY --from=build /ms-playwright /ms-playwright

COPY --from=build /go/bin/playwright /usr/local/bin/playwright

COPY --from=build /bin/test /bin/

RUN playwright install-deps chromium && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENTRYPOINT [ "/bin/test" ]
  • Build and Run docker container: docker build -t test . && docker run --name test test
  • Logs
{"level":"info","time":"2025-01-23T09:16:18Z","message":"Sleeping for 2 seconds"}
{"level":"info","time":"2025-01-23T09:16:20Z","message":"Sleeping for 10 seconds"}
{"level":"info","time":"2025-01-23T09:16:25Z","message":"Sleeping for 2 seconds"}
{"level":"info","time":"2025-01-23T09:16:27Z","message":"Sleeping for 10 seconds"}
  • ps aux output
.-(~)---------------------------------------------------------------------------------------------------------------------------------------(nc@BMDVNITHEESHC)-
`--> docker exec -it test sh
# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 1229240 8648 ?        Ssl  09:25   0:00 /bin/test
root        32  0.0  0.0      0     0 ?        Z    09:25   0:00 [headless_shell] <defunct>
root        33  0.0  0.0      0     0 ?        Z    09:25   0:00 [headless_shell] <defunct>
root        90  0.0  0.0   2388  1312 pts/0    Ss   09:25   0:00 sh
root       116  0.1  0.0      0     0 ?        Z    09:25   0:00 [headless_shell] <defunct>
root       117  0.0  0.0      0     0 ?        Z    09:25   0:00 [headless_shell] <defunct>
root       196  0.1  0.0      0     0 ?        Z    09:25   0:00 [headless_shell] <defunct>
root       197  0.1  0.0      0     0 ?        Z    09:25   0:00 [headless_shell] <defunct>
root       262  0.0  0.0   6000  3076 pts/0    R+   09:25   0:00 ps aux
@nitheeshc nitheeshc added the p2-bug Something isn't working label Jan 23, 2025
@canstand
Copy link
Collaborator

See microsoft/playwright#34230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants