-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
browser.quit doesn't close session #418
Comments
FIrst of all I cannot reproduce it with |
Thanks for the reply. I was able to dedicate more time and check why it works for you and wasn't work for me. The issue seems to happen when using Docker, more specifically the internal network. Here is a repo to quickly reproduce the issue https://github.com/fernandomm/ferrum418#readme Basically when I connect using the internal service name ( browserless ), it fails: $ docker-compose exec app bash -l -c 'bundle exec rails runner /rails/bug.rb http://browserless:3000'
Number of sessions (initial): 0
Number of sessions (before browser.quit): 1
Number of sessions (after browser.quit): 1 But if I connect to the port that is exposed by Docker at the host, it works. In this case I'm using Docker for Mac, but I was also able to reproduce it in Linux and Docker Swarm. $ docker-compose exec app bash -l -c 'bundle exec rails runner /rails/bug.rb http://host.docker.internal:3000'
Number of sessions (initial): 0
Number of sessions (before browser.quit): 1
Number of sessions (after browser.quit): 0 I understand that this issue is related to Docker/network and may not be related to the gem. But I'm trying to investigate it further although I have no experience with the CDP protocol. Do you have any suggestions or helpful tips on what I should look into? Thanks again. |
I'm not sure if there is any difference between Don't expect |
I tried to use page.close but it didn't made any difference. It still left "about:blank" sessions open which were only terminated after Browserless's CONNECTION_TIMEOUT is reached. In one of my tests, I added a simple nginx proxy in front of browserless/chrome container. After that the issue went away. Now browser.quit works as expected inside docker and closes the session immediately. I don't know what nginx does differently but, since I have dedicated more time than expected to this issue, I will just accept and use it :) Thanks a lot for the help. I'm leaving the nginx conf below in case someone experience a similar error. upstream browserless {
zone upstream_dynamic 64k;
server browserless:3000;
}
server {
proxy_next_upstream error timeout http_500 http_503 http_429 non_idempotent;
listen 80;
location / {
proxy_pass http://browserless;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 10;
proxy_send_timeout 900;
proxy_read_timeout 900;
send_timeout 900;
}
} |
Hello! I have almost the exact same issue. I changed my code to call
|
@sloanesturz mind opening a PR with |
Dockerhub link there has rotten. Here is new one: https://docs.docker.com/compose/compose-file/05-services/#init |
@Nakilon good point! |
I'm using Ferrum 0.14 + Ruby 3.2.2 with Browserless. Browserless not only makes it simple to run Chrome headless but it also offers some extras like checking which sessions are active and what it's doing.
So, when I start it there are no sessions:
I start Ferrum and can see that the session is now showing up:
But when i run browser.quit, it doesn't close the session, leaving it open forever:
The session is only closed after I close the IRB console and terminate the process.
When using Ferrum in a long running process like Sidekiq/Puma, this results in thousands of sessions open since the process is never terminated.
I guess that it might also explain the issues with zombie processes previously reported ( #364 ).
Is browser.close the correct way of terminating the session or am I missing something?
The text was updated successfully, but these errors were encountered: