signal termination to geckodriver leaves a firefox behind if no `Delete Session` command was given
(EDIT): you can skip this comment and go to https://github.com/mozilla/geckodriver/issues/291#issuecomment-256596003 that has a more accurate and compact way of reproducing the problem.
Summary
When I kill -15 a geckodriver launched in the shell, there is a firefox process left in the end. I am not sure if this expected or if I am doing something wrong :/
Details
I use 3 terminals. A$,B$,C$ Initially no firefox or geckodriver running
B$ pgrep -fla "(firefox|geckodriver)"
C$ env | grep DISP
DISPLAY=vkcloud2:1
Start geckodriver
C$ geckodriver -vv
B$ pgrep -fla "(firefox|geckodriver)"
22957 geckodriver -vv
Create a new session (and as a consequence a firefox will be created)
A$ curl -X POST localhost:4444/session --data {}
{"sessionId":"8d0f58da-faa7-4ca2-9e30-8d402eefb366","value":{"XULappId":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","acceptSslCerts":false,"appBuildId":"20160919213721","browserName":"firefox","browserVersion":"49.0","command_id":1,"device":"desktop","platform":"LINUX","platformName":"linux","platformVersion":"3.13.0-57-generic","processId":23105,"proxy":{},"raisesAccessibilityExceptions":false,"rotatable":false,"specificationLevel":0,"takesElementScreenshot":true,"takesScreenshot":true,"version":"49.0"}}
Firefox and geckodriver are up and running
B$ pgrep -fla "(firefox|geckodriver)"
22957 geckodriver -vv
23105 /usr/lib/firefox/firefox --marionette --profile /tmp/rust_mozprofile.SdIj945tQmiu
23207 /usr/lib/firefox/plugin-container -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 23105 true tab
B$ pstree -p 22957
geckodriver(22957)─┬─firefox(23105)─┬─Web Content(23207)─┬─{Web Content}(23209)
│ │ ├─{Web Content}(23217)
│ │ ├─{Web Content}(23218)
│ │ ├─{Web Content}(23219)
│ │ ├─{Web Content}(23227)
│ │ ├─{Web Content}(23228)
│ │ ├─{Web Content}(23229)
│ │ ├─{Web Content}(23230)
│ │ ├─{Web Content}(23231)
│ │ ├─{Web Content}(23233)
│ │ ├─{Web Content}(23234)
│ │ ├─{Web Content}(23236)
│ │ ├─{Web Content}(23237)
│ │ ├─{Web Content}(23239)
│ │ ├─{Web Content}(23240)
│ │ ├─{Web Content}(23243)
│ │ ├─{Web Content}(23256)
│ │ └─{Web Content}(23257)
│ ├─{firefox}(23110)
│ ├─{firefox}(23111)
│ ├─{firefox}(23112)
│ ├─{firefox}(23115)
│ ├─{firefox}(23116)
│ ├─{firefox}(23117)
│ ├─{firefox}(23118)
│ ├─{firefox}(23119)
│ ├─{firefox}(23120)
│ ├─{firefox}(23124)
│ ├─{firefox}(23125)
│ ├─{firefox}(23127)
│ ├─{firefox}(23128)
│ ├─{firefox}(23129)
│ ├─{firefox}(23130)
│ ├─{firefox}(23133)
│ ├─{firefox}(23134)
│ ├─{firefox}(23135)
│ ├─{firefox}(23140)
│ ├─{firefox}(23145)
│ ├─{firefox}(23146)
│ ├─{firefox}(23147)
│ ├─{firefox}(23148)
│ ├─{firefox}(23149)
│ ├─{firefox}(23150)
│ ├─{firefox}(23151)
│ ├─{firefox}(23166)
│ ├─{firefox}(23167)
│ ├─{firefox}(23168)
│ ├─{firefox}(23169)
│ ├─{firefox}(23170)
│ ├─{firefox}(23194)
│ ├─{firefox}(23196)
│ ├─{firefox}(23197)
│ ├─{firefox}(23198)
│ ├─{firefox}(23199)
│ ├─{firefox}(23214)
│ ├─{firefox}(23215)
│ ├─{firefox}(23216)
│ ├─{firefox}(23258)
│ ├─{firefox}(23259)
│ ├─{firefox}(23260)
│ ├─{firefox}(23261)
│ └─{firefox}(23262)
├─{geckodriver}(22958)
├─{geckodriver}(22959)
├─{geckodriver}(22960)
└─{geckodriver}(22961)
C$ (in stdout)
(firefox:23105): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:23105): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:23105): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:23105): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1477061453568 Marionette INFO Listening on port 35894
1477061455561 Marionette INFO startBrowser 8d0f58da-faa7-4ca2-9e30-8d402eefb366
(/usr/lib/firefox/plugin-container:23207): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:23207): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:23207): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:23207): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
Let's gracefully kill geckodriver.
B$ kill -15 22957
C$ (in stdout)
Terminated
In the end I still see a firefox running
$ pgrep -fla "(firefox|geckodriver)"
23105 /usr/lib/firefox/firefox --marionette --profile /tmp/rust_mozprofile.SdIj945tQmiu
23207 /usr/lib/firefox/plugin-container -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 23105 true tab
My env
I tried the above with geckodriver 0.10.0 and 0.11.1. The difference was in the output of geckodriver (0.11.1 was more verbose, maybe different log level?) and in the final firefox command:
0.10:
/usr/lib/firefox/firefox --marionette --profile /tmp/rust_mozprofile.SdIj945tQmiu
/usr/lib/firefox/plugin-container -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 23105 true tab
0.11.1:
/usr/lib/firefox/firefox --marionette --profile /tmp/rust_mozprofile.fhzW9bfFwH1m
$ firefox --version
The source is available at https://github.com/mozilla/geckodriver
This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
Mozilla Firefox 49.0
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.2 LTS
Release: 14.04
Codename: trusty
Sending a term signal to geckodriver does not terminate the spawned firefox instance, if Delete Session has not been issued before:
I use the script (1)
Launch geckodriver, and send no delete session command. The firefox process is leftover in the end:
% perl firefox_launch_manually.pl 0
1477560454560 geckodriver INFO Listening on 127.0.0.1:25000
POST /session
1477560456569 mozprofile::profile INFO Using profile path /tmp/rust_mozprofile.5OKfT7FqPRdG
1477560456570 geckodriver::marionette INFO Starting browser /usr/bin/firefox
1477560456572 geckodriver::marionette INFO Connecting to Marionette on localhost:33258
(firefox:26547): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:26547): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:26547): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:26547): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1477560457832 Marionette INFO Listening on port 33258
1477560460135 Marionette INFO startBrowser 8c41f3c2-c636-422c-bb8c-2073c05ea0da
POST /session/8c41f3c2-c636-422c-bb8c-2073c05ea0da/url
(/usr/lib/firefox/plugin-container:26632): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:26632): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:26632): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:26632): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
POST /session/8c41f3c2-c636-422c-bb8c-2073c05ea0da/element
% pgrep -fla firefox; pgrep -fla geckodriver;
26547 /usr/lib/firefox/firefox --marionette --profile /tmp/rust_mozprofile.5OKfT7FqPRdG
26632 /usr/lib/firefox/plugin-container -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 26547 true tab
Launch geckodriver, and send one delete session command. The firefox process is cleared in the end:
% perl firefox_launch_manually.pl 1
1477560425814 geckodriver INFO Listening on 127.0.0.1:25000
POST /session
1477560427826 mozprofile::profile INFO Using profile path /tmp/rust_mozprofile.SKpVRbQG6QBJ
1477560427826 geckodriver::marionette INFO Starting browser /usr/bin/firefox
1477560427828 geckodriver::marionette INFO Connecting to Marionette on localhost:49944
(firefox:26390): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:26390): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:26390): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:26390): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1477560429174 Marionette INFO Listening on port 49944
1477560431391 Marionette INFO startBrowser eca6bd3b-3f05-47fa-ace6-1a09b7b30289
POST /session/eca6bd3b-3f05-47fa-ace6-1a09b7b30289/url
(/usr/lib/firefox/plugin-container:26465): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:26465): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:26465): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/plugin-container:26465): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
POST /session/eca6bd3b-3f05-47fa-ace6-1a09b7b30289/element
DELETE /session/eca6bd3b-3f05-47fa-ace6-1a09b7b30289
[Child 26465] WARNING: pipe error (3): Connection reset by peer: file /build/firefox-XpkqMU/firefox-49.0+build4/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 316
[Child 26465] ###!!! ABORT: Aborting on channel error.: file /build/firefox-XpkqMU/firefox-49.0+build4/ipc/glue/MessageChannel.cpp, line 2052
[Child 26465] ###!!! ABORT: Aborting on channel error.: file /build/firefox-XpkqMU/firefox-49.0+build4/ipc/glue/MessageChannel.cpp, line 2052
% pgrep -fla firefox; pgrep -fla geckodriver;
# nothing shows up
(1) Test script
Sorry for not doing this in rust (don't know yet enough rust to do this)
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);
use Data::Dumper;
use JSON::XS;
my $must_delete = $ARGV[0]; # accept 0 or 1 as argument
my @command = qw{ /usr/local/bin/geckodriver --port 25000 };
my $pid = fork();
die 'Fork failed' if not defined $pid;
if (not $pid) {
exec(@command) or die $!;
}
sleep(2); # wait for geckodriver to launch
my $host = 'localhost:25000';
my $url = '/session';
say "POST $url";
my $res;
$res = decode_json( `curl --silent -X POST ${host}$url --data '{}'` );
my $sessionId = $res->{sessionId};
$url = "/session/$sessionId/url";
say "POST $url";
$res = decode_json( `curl --silent -X POST ${host}$url --data '{"url":"https://www.adzuna.co.uk"}'` );
$url = "/session/$sessionId/element";
say "POST $url";
$res = decode_json( `curl --silent -X POST ${host}$url --data '{"using":"css selector","value":"h1"}'` );
if($must_delete) {
$url = "/session/$sessionId";
say "DELETE $url";
$res = decode_json( `curl --silent -X DELETE ${host}$url --data '{}'` );
}
kill(15, $pid);
perl firefox_launch_manually.pl 0 perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_PAPER = "bn_BD", LC_ADDRESS = "bn_BD", LC_MONETARY = "bn_BD", LC_NUMERIC = "bn_BD", LC_TELEPHONE = "bn_BD", LC_IDENTIFICATION = "bn_BD", LC_MEASUREMENT = "bn_BD", LC_TIME = "bn_BD", LC_NAME = "bn_BD", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). Can't open perl script "firefox_launch_manually.pl": No such file or directory root@ip-10-0-1-140:~# env | grep DISP DISPLAY=vkcloud2:1 root@ip-10-0-1-140:~#
There is basically https://bugzilla.mozilla.org/show_bug.cgi?id=1430064, which handles this particular issue.