Closed Andiedie closed 2 years ago
I have seen #298 but did't find anything useful, because I use docker image in aws lambda.
For more infomation, I run chromedp/headless-shell directly on ec2 and aws lambda using the same args in golang code.
FROM chromedp/headless-shell
ENTRYPOINT [ "/headless-shell/headless-shell", "--no-first-run", "--no-default-browser-check", "--no-sandbox", "--disable-gpu", "--headless", "--hide-scrollbars", "--mute-audio", "--no-zygote", "--user-data-dir=/tmp/chrome-user-data-dir", "--homedir=/tmp/chrome-home", "--data-path=/tmp/chrome-data-path", "--disk-cache-dir=/tmp/chrome-disk-cache-dir", "--remote-debugging-port=9222", "--remote-debugging-address=0.0.0.0", "--disable-dev-shm-usage", "--enable-features=NetworkService,NetworkServiceInProcess" ]
Log on ec2 (Works)
$ docker run --rm -it test
[0601/050439.195829:INFO:content_main_runner_impl.cc(1144)] Chrome is running in full browser mode.
DevTools listening on ws://0.0.0.0:9222/devtools/browser/a3478411-e6c4-41f1-bb64-44e0f4b6dbcc
[0601/050439.206209:ERROR:devtools_http_handler.cc(291)] Error writing DevTools active port to file
[0601/050439.213214:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0601/050439.213275:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is angle, ANGLE is swiftshader
[0601/050439.213335:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0601/050439.213357:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0601/050439.213363:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0601/050439.213380:ERROR:gpu_init.cc(86)] CollectGraphicsInfo failed.
[0601/050439.215571:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0601/050439.234087:WARNING:child_process_launcher_helper_posix.cc(83)] Ignoring invalid file snapshot_blob.bin
[0601/050439.243838:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0601/050439.243902:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is angle, ANGLE is swiftshader
[0601/050439.243968:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0601/050439.244002:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0601/050439.244020:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0601/050439.244045:ERROR:gpu_init.cc(86)] CollectGraphicsInfo failed.
[0601/050439.247142:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0601/050439.256784:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is disabled, ANGLE is
Log on aws lambda (does't work)
START RequestId: 201b0ec5-c1c1-4bb8-a055-c2658305d6ea Version: $LATEST
[0601/045722.126366:INFO:content_main_runner_impl.cc(1144)] Chrome is running in full browser mode.
[0601/045722.134623:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
[0601/045722.134609:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
prctl(PR_SET_NO_NEW_PRIVS) failed
DevTools listening on ws://0.0.0.0:9222/devtools/browser/8277e70c-1ad8-4465-9fc0-ea1258c28c3d
[0601/045722.148364:ERROR:gpu_process_host.cc(973)] GPU process exited unexpectedly: exit_code=133
[0601/045722.148388:WARNING:gpu_process_host.cc(1273)] The GPU process has crashed 1 time(s)
[0601/045722.161952:WARNING:child_process_launcher_helper_posix.cc(83)] Ignoring invalid file snapshot_blob.bin
prctl(PR_SET_NO_NEW_PRIVS) failed
prctl(PR_SET_NO_NEW_PRIVS) failed
[0601/045722.164563:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
[0601/045722.185013:ERROR:gpu_process_host.cc(973)] GPU process exited unexpectedly: exit_code=133
[0601/045722.185042:WARNING:gpu_process_host.cc(1273)] The GPU process has crashed 2 time(s)
prctl(PR_SET_NO_NEW_PRIVS) failed
[0601/045722.186685:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
[0601/045722.201714:ERROR:gpu_process_host.cc(973)] GPU process exited unexpectedly: exit_code=133
[0601/045722.201756:WARNING:gpu_process_host.cc(1273)] The GPU process has crashed 3 time(s)
prctl(PR_SET_NO_NEW_PRIVS) failed
[0601/045722.203623:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
[0601/045722.218695:ERROR:gpu_process_host.cc(973)] GPU process exited unexpectedly: exit_code=133
[0601/045722.218727:WARNING:gpu_process_host.cc(1273)] The GPU process has crashed 4 time(s)
prctl(PR_SET_NO_NEW_PRIVS) failed
[0601/045722.220732:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
[0601/045722.235865:ERROR:gpu_process_host.cc(973)] GPU process exited unexpectedly: exit_code=133
[0601/045722.235899:WARNING:gpu_process_host.cc(1273)] The GPU process has crashed 5 time(s)
prctl(PR_SET_NO_NEW_PRIVS) failed
[0601/045722.237839:ERROR:file_util_posix.cc(932)] fallocate: Operation not permitted (1)
[0601/045722.253183:ERROR:gpu_process_host.cc(973)] GPU process exited unexpectedly: exit_code=133
[0601/045722.253214:WARNING:gpu_process_host.cc(1273)] The GPU process has crashed 6 time(s)
[0601/045722.253239:FATAL:gpu_data_manager_impl_private.cc(450)] GPU process isn't usable. Goodbye.
#0 0x55a64ee43369 (/headless-shell/headless-shell+0x6dbb368)
#1 0x55a64ed77023 (/headless-shell/headless-shell+0x6cef022)
#2 0x55a64ed8db80 (/headless-shell/headless-shell+0x6d05b7f)
#3 0x55a64cefa7a7 (/headless-shell/headless-shell+0x4e727a6)
#4 0x55a64cef712c (/headless-shell/headless-shell+0x4e6f12b)
#5 0x55a64cef58cb (/headless-shell/headless-shell+0x4e6d8ca)
#6 0x55a64cf01829 (/headless-shell/headless-shell+0x4e79828)
#7 0x55a64cf02ff4 (/headless-shell/headless-shell+0x4e7aff3)
#8 0x55a64cd1eb7b (/headless-shell/headless-shell+0x4c96b7a)
#9 0x55a64c9d1ede (/headless-shell/headless-shell+0x4949edd)
#10 0x55a64f414b98 (/headless-shell/headless-shell+0x738cb97)
#11 0x55a64f41ac23 (/headless-shell/headless-shell+0x7392c22)
#12 0x55a64f16c47d (/headless-shell/headless-shell+0x70e447c)
#13 0x55a64f420a2d (/headless-shell/headless-shell+0x7398a2c)
#14 0x55a64f422949 (/headless-shell/headless-shell+0x739a948)
#15 0x55a64f167545 (/headless-shell/headless-shell+0x70df544)
#16 0x55a64f1682c7 (/headless-shell/headless-shell+0x70e02c6)
#17 0x55a64c984d40 (/headless-shell/headless-shell+0x48fcd3f)
#18 0x55a64f191fd0 (/headless-shell/headless-shell+0x7109fcf)
#19 0x55a64ecbcfb2 (/headless-shell/headless-shell+0x6c34fb1)
#20 0x55a64eddf5b9 (/headless-shell/headless-shell+0x6d575b8)
#21 0x55a64ee044b4 (/headless-shell/headless-shell+0x6d7c4b3)
#22 0x55a64ee03b5e (/headless-shell/headless-shell+0x6d7bb5d)
#23 0x55a64ee04cf2 (/headless-shell/headless-shell+0x6d7ccf1)
#24 0x55a64ee7c8f5 (/headless-shell/headless-shell+0x6df48f4)
#25 0x55a64ee05299 (/headless-shell/headless-shell+0x6d7d298)
#26 0x55a64edc3da0 (/headless-shell/headless-shell+0x6d3bd9f)
#27 0x55a64cd3be95 (/headless-shell/headless-shell+0x4cb3e94)
#28 0x55a64cd3d872 (/headless-shell/headless-shell+0x4cb5871)
#29 0x55a64ed6d54b (/headless-shell/headless-shell+0x6ce554a)
#30 0x55a64d689b33 (/headless-shell/headless-shell+0x5601b32)
#31 0x55a64d68b2b4 (/headless-shell/headless-shell+0x56032b3)
#32 0x55a64d68ad30 (/headless-shell/headless-shell+0x5602d2f)
#33 0x55a64d688747 (/headless-shell/headless-shell+0x5600746)
#34 0x55a64d68882e (/headless-shell/headless-shell+0x560082d)
#35 0x55a64ed68e9d (/headless-shell/headless-shell+0x6ce0e9c)
#36 0x55a64ed68cfe (/headless-shell/headless-shell+0x6ce0cfd)
#37 0x55a64ed68a45 (/headless-shell/headless-shell+0x6ce0a44)
#38 0x7fd055406d0a __libc_start_main
#39 0x55a64b5f01ea _start
Task trace:
#0 0x55a64f19237c (/headless-shell/headless-shell+0x710a37b)
END RequestId: 201b0ec5-c1c1-4bb8-a055-c2658305d6ea
REPORT RequestId: 201b0ec5-c1c1-4bb8-a055-c2658305d6ea Duration: 180.60 ms Billed Duration: 181 ms Memory Size: 10240 MB Max Memory Used: 84 MB
RequestId: 201b0ec5-c1c1-4bb8-a055-c2658305d6ea Error: Runtime exited with error: signal: trace/breakpoint trap
Runtime.ExitError
For more infomation, aws lambda only allows to write file in /tmp
, other path is read-only.
I have tried the following images:
Except for 102.0.5005.63
(which is tagged as latest
as of now and is used in this issue report), all the others can't even start (no CDP messages, no output from the headless-shell).
So, unfortunately, chromedp/headless-shell
just does not work on AWS Lambda.
Updated: The listed images failed the same way after I increase the timeout of the AWS Lambda function to 20s.
Thanks for quick reply.
Do you have any idea about why it fails, or any other way to run chromedp on AWS Lambda?
I try to change image of Dockerfile in repo to chromedp/headless-shell:101.0.4951.7
FROM golang:alpine AS builder
RUN apk add git
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main
FROM chromedp/headless-shell:101.0.4951.7
RUN apt-get update && \
apt-get install -y dumb-init musl-dev && \
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1 &&\
rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/main .
ENTRYPOINT [ "dumb-init", "--" ]
CMD [ "./main" ]
It behave the same as chromedp/headless-shell:latest
(stuck after last log {"id":3,"sessionId":"341D47C727A583D1E232D49953E705FE","method":"Runtime.enable"}
)
START RequestId: ce42768d-8a0b-4169-a25c-17e4b2317919 Version: $LATEST
2022/06/01 12:00:28 -> {"id":1,"method":"Target.setDiscoverTargets","params":{"discover":true}}
2022/06/01 12:00:29 <- {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"3512005a-c14b-41b8-8a74-cf09d1a8a154","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}}
2022/06/01 12:00:29 <- {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"6189F03BE61B2DD54665C50FF111DA97","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"5C128ACB50B7AFEB7AB7FA9D81BF3777"}}}
2022/06/01 12:00:29 <- {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"c392f8af-ca14-48c9-ac00-46113b2210a8","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}}
2022/06/01 12:00:29 <- {"id":1,"result":{}}
2022/06/01 12:00:29 -> {"id":2,"method":"Target.attachToTarget","params":{"targetId":"6189F03BE61B2DD54665C50FF111DA97","flatten":true}}
2022/06/01 12:00:29 <- {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"6189F03BE61B2DD54665C50FF111DA97","type":"page","title":"","url":"","attached":true,"canAccessOpener":false,"browserContextId":"5C128ACB50B7AFEB7AB7FA9D81BF3777"}}}
2022/06/01 12:00:29 <- {"method":"Target.attachedToTarget","params":{"sessionId":"341D47C727A583D1E232D49953E705FE","targetInfo":{"targetId":"6189F03BE61B2DD54665C50FF111DA97","type":"page","title":"","url":"","attached":true,"canAccessOpener":false,"browserContextId":"5C128ACB50B7AFEB7AB7FA9D81BF3777"},"waitingForDebugger":false}}
2022/06/01 12:00:29 <- {"id":2,"result":{"sessionId":"341D47C727A583D1E232D49953E705FE"}}
2022/06/01 12:00:29 -> {"id":3,"sessionId":"341D47C727A583D1E232D49953E705FE","method":"Runtime.enable"}
END RequestId: ce42768d-8a0b-4169-a25c-17e4b2317919
REPORT RequestId: ce42768d-8a0b-4169-a25c-17e4b2317919 Duration: 20016.95 ms Billed Duration: 21390 ms Memory Size: 10240 MB Max Memory Used: 124 MB Init Duration: 1372.23 ms
2022-06-01T12:00:35.069Z ce42768d-8a0b-4169-a25c-17e4b2317919 Task timed out after 20.02 seconds
You're correct. I got the same result after I increase the timeout of the AWS Lambda function.
As the "Log on aws lambda (does't work)" shows, it failed because GPU process isn't usable. Goodbye.
.
I have tried passing the following options to headless-shell, but it still does not work:
--single-process
--disable-gpu-shader-disk-cache
--disable-gpu-early-init
And I just tried chromedp/headless-shell:96.0.4664.93
(just because I have pulled it before). It failed with another reason:
[0601/131811.991312:FATAL:viz_main_impl.cc(239)] Check failed: gl::GetGLImplementation() == gl::kGLImplementationDisabled (0 vs. 8)
.
It seems there are too many issues to run chromedp/headless-shell
. I don't have any idea about how to address them.
I found that adding --single-process
flag will crash the container.
Without --single-process
(Works)
$ docker run --rm -it chromedp/headless-shell --no-first-run --no-default-browser-check --no-sandbox --disable-gpu --headless --hide-scrollbars --mute-audio --no-zygote --user-data-dir=/tmp/chrome-user-data-dir --homedir=/tmp/chrome-home --data-path=/tmp/chrome-data-path --disk-cache-dir=/tmp/chrome-disk-cache-dir --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --disable-dev-shm-usage --enable-features=NetworkService,NetworkServiceInProcess --disable-gpu-shader-disk-cache disable-gpu-early-init --disable-gpu-compositing --disable-gpu-sandbox
[0602/025438.019167:INFO:content_main_runner_impl.cc(1144)] Chrome is running in full browser mode.
DevTools listening on ws://0.0.0.0:9222/devtools/browser/bdae72ef-ffee-4600-b6a6-fe1f7d9b3c75
[0602/025438.029201:ERROR:devtools_http_handler.cc(291)] Error writing DevTools active port to file
[0602/025438.036425:WARNING:child_process_launcher_helper_posix.cc(83)] Ignoring invalid file snapshot_blob.bin
[0602/025438.036966:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0602/025438.037037:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is angle, ANGLE is swiftshader
[0602/025438.037140:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0602/025438.037255:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0602/025438.037299:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0602/025438.037461:ERROR:gpu_init.cc(86)] CollectGraphicsInfo failed.
[0602/025438.045644:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[0602/025438.048441:WARNING:directory_listing.cc(24)] Missing resource: directory listing header
[0602/025438.068671:ERROR:gpu_init.cc(481)] Passthrough is not supported, GL is disabled, ANGLE is
[0602/025438.086773:INFO:CONSOLE(1)] "Uncaught ReferenceError: start is not defined", source: file:/// (1)
[0602/025438.087195:INFO:CONSOLE(2)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (2)
[0602/025438.087607:INFO:CONSOLE(3)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (3)
[0602/025438.088018:INFO:CONSOLE(4)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (4)
[0602/025438.088105:INFO:CONSOLE(5)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (5)
[0602/025438.088502:INFO:CONSOLE(6)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (6)
[0602/025438.088653:INFO:CONSOLE(7)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (7)
[0602/025438.088985:INFO:CONSOLE(8)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (8)
[0602/025438.089231:INFO:CONSOLE(9)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (9)
[0602/025438.089581:INFO:CONSOLE(10)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (10)
[0602/025438.090077:INFO:CONSOLE(11)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (11)
[0602/025438.090400:INFO:CONSOLE(12)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (12)
[0602/025438.090477:INFO:CONSOLE(13)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (13)
[0602/025438.090822:INFO:CONSOLE(14)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (14)
[0602/025438.091078:INFO:CONSOLE(15)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (15)
[0602/025438.091298:INFO:CONSOLE(16)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (16)
[0602/025438.091549:INFO:CONSOLE(17)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (17)
[0602/025438.091817:INFO:CONSOLE(18)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (18)
[0602/025438.092270:INFO:CONSOLE(19)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (19)
[0602/025438.092487:INFO:CONSOLE(20)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (20)
[0602/025438.092576:INFO:CONSOLE(21)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (21)
[0602/025438.092816:INFO:CONSOLE(22)] "Uncaught ReferenceError: addRow is not defined", source: file:/// (22)
With --single-process
(Doesn't work)
$ docker run --rm -it chromedp/headless-shell --no-first-run --no-default-browser-check --no-sandbox --disable-gpu --headless --hide-scrollbars --mute-audio --no-zygote --user-data-dir=/tmp/chrome-user-data-dir --homedir=/tmp/chrome-home --data-path=/tmp/chrome-data-path --disk-cache-dir=/tmp/chrome-disk-cache-dir --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --disable-dev-shm-usage --enable-features=NetworkService,NetworkServiceInProcess --disable-gpu-shader-disk-cache disable-gpu-early-init --disable-gpu-compositing --disable-gpu-sandbox --single-process
[0602/025632.802722:INFO:content_main_runner_impl.cc(1144)] Chrome is running in full browser mode.
DevTools listening on ws://0.0.0.0:9222/devtools/browser/680709ac-91b4-48a5-b9bf-5cba140835b6
[0602/025632.812484:ERROR:devtools_http_handler.cc(291)] Error writing DevTools active port to file
[0602/025632.813066:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0602/025632.813149:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0602/025632.813175:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0602/025632.813192:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0602/025632.813278:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0602/025632.813302:ERROR:gpu_info_collector.cc(93)] gl::init::CreateGLContext failed
[0602/025632.813337:ERROR:gpu_info_collector.cc(348)] Could not create context for info collection.
[0602/025632.824407:ERROR:gl_context_egl.cc(355)] eglCreateContext failed with error EGL_BAD_ATTRIBUTE
[0602/025632.824445:ERROR:gpu_channel_manager.cc(831)] ContextResult::kFatalFailure: Failed to create shared context for virtualization.
[0602/025632.824461:ERROR:shared_image_stub.cc(537)] SharedImageStub: unable to create context
[0602/025632.824489:ERROR:gpu_channel.cc(572)] GpuChannel: Failed to create SharedImageStub
[0602/025632.842847:FATAL:gpu_client.cc(107)] Check failed: channel_handle.is_valid() == status == GpuHostImpl::EstablishChannelStatus::kSuccess (0 vs. 1)
#0 0x55dc66968369 (/headless-shell/headless-shell+0x6dbb368)
#1 0x55dc6689c023 (/headless-shell/headless-shell+0x6cef022)
#2 0x55dc668b2b80 (/headless-shell/headless-shell+0x6d05b7f)
#3 0x55dc668b366e (/headless-shell/headless-shell+0x6d0666d)
#4 0x55dc683aaa73 (/headless-shell/headless-shell+0x87fda72)
#5 0x55dc683abbb1 (/headless-shell/headless-shell+0x87febb0)
#6 0x55dc683abaf9 (/headless-shell/headless-shell+0x87feaf8)
#7 0x55dc683ae143 (/headless-shell/headless-shell+0x8801142)
#8 0x55dc683b046c (/headless-shell/headless-shell+0x880346b)
#9 0x55dc683b03b0 (/headless-shell/headless-shell+0x88033af)
#10 0x55dc645e666a (/headless-shell/headless-shell+0x4a39669)
#11 0x55dc66c8f7f9 (/headless-shell/headless-shell+0x70e27f8)
#12 0x55dc66c97aa9 (/headless-shell/headless-shell+0x70eaaa8)
#13 0x55dc66c9126d (/headless-shell/headless-shell+0x70e426c)
#14 0x55dc66c9d3b7 (/headless-shell/headless-shell+0x70f03b6)
#15 0x55dc66c9c85c (/headless-shell/headless-shell+0x70ef85b)
#16 0x55dc66c97aa9 (/headless-shell/headless-shell+0x70eaaa8)
#17 0x55dc66c8c9fc (/headless-shell/headless-shell+0x70df9fb)
#18 0x55dc66c8d515 (/headless-shell/headless-shell+0x70e0514)
#19 0x55dc66c8d2b9 (/headless-shell/headless-shell+0x70e02b8)
#20 0x55dc644a9d40 (/headless-shell/headless-shell+0x48fcd3f)
#21 0x55dc66cb6fd0 (/headless-shell/headless-shell+0x7109fcf)
#22 0x55dc667e1fb2 (/headless-shell/headless-shell+0x6c34fb1)
#23 0x55dc669045b9 (/headless-shell/headless-shell+0x6d575b8)
#24 0x55dc669294b4 (/headless-shell/headless-shell+0x6d7c4b3)
#25 0x55dc66928b5e (/headless-shell/headless-shell+0x6d7bb5d)
#26 0x55dc66929cf2 (/headless-shell/headless-shell+0x6d7ccf1)
#27 0x55dc669a18f5 (/headless-shell/headless-shell+0x6df48f4)
#28 0x55dc6692a299 (/headless-shell/headless-shell+0x6d7d298)
#29 0x55dc668e8da0 (/headless-shell/headless-shell+0x6d3bd9f)
#30 0x55dc64860e95 (/headless-shell/headless-shell+0x4cb3e94)
#31 0x55dc64862872 (/headless-shell/headless-shell+0x4cb5871)
#32 0x55dc6689254b (/headless-shell/headless-shell+0x6ce554a)
#33 0x55dc651aeb33 (/headless-shell/headless-shell+0x5601b32)
#34 0x55dc651b02b4 (/headless-shell/headless-shell+0x56032b3)
#35 0x55dc651afd30 (/headless-shell/headless-shell+0x5602d2f)
#36 0x55dc651ad747 (/headless-shell/headless-shell+0x5600746)
#37 0x55dc651ad82e (/headless-shell/headless-shell+0x560082d)
#38 0x55dc6688de9d (/headless-shell/headless-shell+0x6ce0e9c)
#39 0x55dc6688dcfe (/headless-shell/headless-shell+0x6ce0cfd)
#40 0x55dc6688da45 (/headless-shell/headless-shell+0x6ce0a44)
#41 0x7fd6878a0d0a __libc_start_main
#42 0x55dc631151ea _start
Task trace:
#0 0x55dc66cb737c (/headless-shell/headless-shell+0x710a37b)
#1 0x55dc667e21a1 (/headless-shell/headless-shell+0x6c351a0)
#2 0x55dc667df1ba (/headless-shell/headless-shell+0x6c321b9)
#3 0x55dc66cb6a49 (/headless-shell/headless-shell+0x7109a48)
#4 0x55dc667dd0fb (/headless-shell/headless-shell+0x6c300fa)
Task trace buffer limit hit, update PendingTask::kTaskBacktraceLength to increase.
IT WORKS! Checkout this example repo.
I just gave up chromedp/headless-shell
and turned into debian
with manually installed chromium.
Launch chromium with args:
--headless
--no-sandbox
--disable-setuid-sandbox
--disable-dev-shm-usage
--single-process
--no-zygote
FROM golang AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main
FROM debian AS runtime
RUN apt-get update && apt-get install -y chromium
COPY --from=builder /app/main .
ENTRYPOINT [ "./main" ]
I'm going to reopen this issue in the hope that we can make chromedp/headless-shell
work in aws lambda (since chromium works).
@Andiedie Would you like to give https://hub.docker.com/r/zeke/headless-shell/tags a try? It should work on AWS Lambda now. Please note that two more flags are required:
--use-gl=angle
--use-angle=swiftshader
See chromedp/docker-headless-shell#18 for more information.
Thanks for updating.
But sorry I am a little bit busy now, I will try it as soon as I can.
Hey there, I have tried running app on lambda with image zeke/headless-shell:102.0.5005.115 and everything works.
FROM golang AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main
FROM zeke/headless-shell:102.0.5005.115
COPY --from=builder /app/main .
ENTRYPOINT [ "./main" ]
Thank you for confirming! We will fix chromedp/headless-shell
later.
@Andiedie Would you like to give https://hub.docker.com/r/zeke/headless-shell/tags a try? It should work on AWS Lambda now. Please note that two more flags are required:
--use-gl=angle
--use-angle=swiftshader
See chromedp/docker-headless-shell#18 for more information.
Hey there, I got similar issue when running on aws lambda, which is stuck after {"id":3,"sessionId":"341D47C727A583D1E232D49953E705FE","method":"Runtime.enable"}) My dockerfile is very similar to @Andiedie's one
FROM golang:1.18-alpine AS builder
WORKDIR /app
RUN apk add go git
RUN go env -w GOPROXY=direct
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main
FROM zeke/headless-shell:102.0.5005.115
RUN apt-get update; apt-get install -y dumb-init musl-dev ca-certificates
COPY --from=builder /app/main .
ENTRYPOINT ["./main"]
I'm not sure where to add these two flags you mentioned
--use-gl=angle
--use-angle=swiftshader
since run on AWS lambda is just build the container, push to the ECR repository and then update and invoke the function?
I'm also curious if this fix has been added to the chromedp/headless-shell:latest?
Thank you very much for your time and help!
The entry point is your app ./main
. So the browser is started by your app. You can specify --use-gl=angle
and --use-angle=swiftshader
with chromedp.Flag
in your code:
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("use-gl", "angle"),
chromedp.Flag("use-angle", "swiftshader"),
)
I'm also curious if this fix has been added to the chromedp/headless-shell:latest?
Yes. It seems that there is something wrong with the builder. We are looking into it.
@celianiu The docker images have just been updated. You can try them if you like.
stable
and latest
)beta
)dev
)Thanks for the quick reply! I just tested will the latest version with the following flags:
opts := []chromedp.ExecAllocatorOption{
chromedp.Headless,
chromedp.NoSandbox,
chromedp.WindowSize(1200, 1000),
// chromedp.Flag("disable-setuid-sandbox", true),
chromedp.Flag("disable-dev-shm-usage", true),
// chromedp.Flag("single-process", true),
//chromedp.Flag("no-zygote", true),
chromedp.Flag("use-gl", "angle"),
chromedp.Flag("use-angle", "swiftshader"),
}
I noticed that disable-dev-shm-usage
seems also necessary, and the no-zygote
flag seems also cause the program stuck.(Not sure if I tested correctly)
And when I removed that flag, I received the context canceled
error.
2022/07/05 13:58:08 -> {"id":1,"method":"Target.setDiscoverTargets","params":{"discover":true}}
2022/07/05 13:58:08 <- {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"187B4DA22EBCC3C85FA292F447A83B2C","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"7FDE17DD2B4FCF743EE7945F2F63275D"}}}
2022/07/05 13:58:08 <- {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"dd7bf2ba-6750-496b-8d74-e63105a0fcc3","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}}
2022/07/05 13:58:08 <- {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"e3acc6d7-c6ee-4841-970f-0d80b8a81823","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}}
2022/07/05 13:58:08 <- {"id":1,"result":{}}
2022/07/05 13:58:08 -> {"id":2,"method":"Target.attachToTarget","params":{"targetId":"187B4DA22EBCC3C85FA292F447A83B2C","flatten":true}}
2022/07/05 13:58:08 <- {"method":"Target.targetCrashed","params":{"targetId":"187B4DA22EBCC3C85FA292F447A83B2C","status":"failed to launch","errorCode":1002}}
2022/07/05 13:58:08 <- {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"187B4DA22EBCC3C85FA292F447A83B2C","type":"page","title":"","url":"","attached":true,"canAccessOpener":false,"browserContextId":"7FDE17DD2B4FCF743EE7945F2F63275D"}}}
2022/07/05 13:58:08 <- {"method":"Target.attachedToTarget","params":{"sessionId":"6A3B82D2AC85C87D8632529FF8DC2663","targetInfo":{"targetId":"187B4DA22EBCC3C85FA292F447A83B2C","type":"page","title":"","url":"","attached":true,"canAccessOpener":false,"browserContextId":"7FDE17DD2B4FCF743EE7945F2F63275D"},"waitingForDebugger":false}}
2022/07/05 13:58:08 <- {"id":2,"result":{"sessionId":"6A3B82D2AC85C87D8632529FF8DC2663"}}
2022/07/05 13:58:08 -> {"id":3,"sessionId":"6A3B82D2AC85C87D8632529FF8DC2663","method":"Runtime.enable"}
2022/07/05 13:58:09 context canceled
END RequestId: 20f09141-7911-41e9-8ff8-94ef51bdb10f
REPORT RequestId: 20f09141-7911-41e9-8ff8-94ef51bdb10f Duration: 1160.96 ms Billed Duration: 2556 ms Memory Size: 512 MB Max Memory Used: 122 MB Init Duration: 1394.25 ms
RequestId: 20f09141-7911-41e9-8ff8-94ef51bdb10f Error: Runtime exited with error: exit status 1
Runtime.ExitError
I saw you mentioned this error in FAQ, but I didn't get this when I ran locally, so I was wondering if this error could be caused by lambda? or if there might be anything wrong with my flag setting?
Can you provide a minimal reproducer? You can create one based on https://github.com/Andiedie/chromedp-aws-lambda-example.
Thanks! I got it fixed! It's the flag-setting issue. It works with following:
opts := []chromedp.ExecAllocatorOption{
chromedp.Headless,
chromedp.NoSandbox,
chromedp.WindowSize(1200, 1000),
chromedp.Flag("disable-setuid-sandbox", true),
chromedp.Flag("disable-dev-shm-usage", true),
chromedp.Flag("single-process", true),
chromedp.Flag("no-zygote", true),
chromedp.Flag("use-gl", "angle"),
chromedp.Flag("use-angle", "swiftshader"),
}
Other than the two flags you mentioned, the rest of the flags seems also necessary to run on lambda.
Can you remove the two options (use-gl
and use-angle
) and try again? Maybe they are not needed. Thank you!
Sorry for the late reply! It works fine without that two flags (use-gl and use-angle). Only require these:
opts := []chromedp.ExecAllocatorOption{
chromedp.Headless,
chromedp.NoSandbox,
chromedp.WindowSize(1200, 1000),
chromedp.Flag("disable-setuid-sandbox", true),
chromedp.Flag("disable-dev-shm-usage", true),
chromedp.Flag("single-process", true),
chromedp.Flag("no-zygote", true),
}
Again, thank you very much for your time and support!
@celianiu thanks so much for providing your solution. It still works!
What versions are you running?
What did you do? Include clear steps.
Here is an example repo. I want to deploy it to aws lambda.
Code snippet
This code (without docker) run perfectly on my M1 macbook, and built docker container run perfectly on AWS EC2.
But when I deploy it to aws lambda, it just stuck after last log
2022/06/01 04:13:38 -> {"id":3,"sessionId":"26082765C593E944A783B371227B397A","method":"Runtime.enable"}
.What did you expect to see?
I can run it on aws lambda.
Log on ec2 running perfectly
What did you see instead?
It stuck and timeout (aws lambda timeout).
Log on aws lambda.