Bug 40985

Summary: Firefox hangs when clicking on "finish" at the end of the setup wizard
Product: UCS Reporter: Alexander Kläser <klaeser>
Component: UMC - Setup wizardAssignee: Eduard Mai <mai>
Status: CLOSED FIXED QA Contact: Alexander Kläser <klaeser>
Severity: normal    
Priority: P5 CC: best, mai
Version: UCS 4.1   
Target Milestone: UCS 4.1-2-errata   
Hardware: Other   
OS: Linux   
See Also: https://bugzilla.mozilla.org/show_bug.cgi?id=1105891
https://bugzilla.mozilla.org/show_bug.cgi?id=662444
https://forge.univention.org/bugzilla/show_bug.cgi?id=38866
https://forge.univention.org/bugzilla/show_bug.cgi?id=43375
What kind of report is it?: --- What type of bug is this?: ---
Who will be affected by this bug?: --- How will those affected feel about the bug?: ---
User Pain: Enterprise Customer affected?:
School Customer affected?: ISV affected?:
Waiting Support: Flags outvoted (downgraded) after PO Review:
Ticket number: Bug group (optional):
Max CVSS v3 score:
Bug Depends on:    
Bug Blocks: 40006    

Description Alexander Kläser univentionstaff 2016-04-04 13:29:24 CEST
With the changes of Bug 40046, Firefox is hanging when clicking on "finish" on the last page of the setup wizard. "finish" will trigger a JS function which calls window.close(). This problems only seems to be reproducible in a setup with DHCP, static IP addresses seem to work fine.
Comment 1 Alexander Kläser univentionstaff 2016-04-04 13:33:53 CEST
https://bugzilla.mozilla.org/show_bug.cgi?id=1105891#c24
→ Maybe this problem is related to some problem with the profile?

https://bugzilla.mozilla.org/show_bug.cgi?id=662444
→ The shutdown process will trigger some shutdown operations which might end up in a deadlock. Not sure, but I had the impression that Bug 38866 might be related to this problem as well. I observed FF with a normal load and it did not hang with DHCP.

Firefox also reports errors due to dbus missing (→ Bug 36168), not sure whether this could be related.
Comment 2 Alexander Kläser univentionstaff 2016-04-04 13:36:29 CEST
In about:config → toolkit.asyncshutdown.timeout.crash could be set to 1 (ms) (default value is 60000ms). This could be worth a try. Otherwise, I could not detect any other config parameters that might be of interest.

Another workaround would be to install a temporary web service which allows to kill the Firefox session.
Comment 3 Alexander Kläser univentionstaff 2016-04-04 13:48:19 CEST
Problem has been reproduced in "demo mode" and when joining the system as UCS master.
Comment 4 Eduard Mai univentionstaff 2016-04-06 14:38:03 CEST
Revision 68429: Closing Firefox by umcp command instead of window.close
Successful build
Package: univention-system-setup
Version: 9.1.4-5.954.201604061432
Branch: ucs_4.1-0
Scope: appliance
Comment 5 Alexander Kläser univentionstaff 2016-04-06 15:04:55 CEST
Really nice fix :) ! Just some minor issues...

(a) this.umcpCommand('setup/closefirefox', {keep_alive: true}, false);
→ As no data is transferred, this could be rather:
this.umcpCommand('setup/closefirefox', {}, false);

(b) def close_firefox(self, request): ...
→ Could have a simple_response decorator, then without the "request" parameter.
Comment 6 Florian Best univentionstaff 2016-04-06 15:20:57 CEST
+	def close_firefox(self, request):
+		PATH_BROWSER_PID = '/var/cache/univention-system-setup/browser.pid'
+		try:
+			fpid = open(PATH_BROWSER_PID)
+			strpid = fpid.readline().strip()
+			pid = int(strpid)
+			p = psutil.Process(pid)
+			p.kill()
+		except IOError:
+			print 'WARN: cannot open browser PID file: %s' % PATH_BROWSER_PID
+		except ValueError:
+			print 'ERROR: browser PID is not a number: "%s"' % strpid
+		except psutil.NoSuchProcess:
+			print 'ERROR: cannot kill process with PID: %s' % pid

1. you don't need to define a constant for a variable which is only used once
2. use "with open(filename) as fd:" when opening files (to automatically close them)
3. don't use print, use MODULE.error()

try:
    with open('/var/cache/univention-system-setup/browser.pid', 'rb') as fd:
       pid = int(fd.readline().strip())
       process = psutil.Process(pid)
       p.kill()
except IOError as exc:
   MODULE.error('cannot open PID file: %s' % (exc,))
…
Comment 7 Eduard Mai univentionstaff 2016-04-06 18:44:18 CEST
Added suggestions from Comment 5 and 6.

Rev. 68438: Code cleanup
Rev. 68439: Corrected typo
Successful build
Package: univention-system-setup
Version: 9.1.4-7.956.201604061840
User: emai
Branch: ucs_4.1-0
Comment 8 Florian Best univentionstaff 2016-04-07 06:21:38 CEST
What in case of an error? Maybe the window.close() should be readded to the error handler of the umcpCommand deferred - even if it takes 5 minutes then it's better than closing it never.
Comment 9 Eduard Mai univentionstaff 2016-04-08 14:04:24 CEST
Rev. 68509: Added error handling.
Package: univention-system-setup
Version: 9.1.4-8.957.201604081401
Branch: ucs_4.1-0
Scope: appliance
Comment 10 Florian Best univentionstaff 2016-04-12 14:45:44 CEST
Just a small hint:
You don't have to use psutil to kill a process. You can simply use os.kill(pid).
Comment 11 Florian Best univentionstaff 2016-04-12 14:50:17 CEST
os.kill(pid, 9)

9 is signal.SIGKILL.
15 is signal.SIGTERM.
Maybe SIGTERM is better?
Comment 12 Alexander Kläser univentionstaff 2016-04-14 16:58:57 CEST
(In reply to Florian Best from comment #11)
> os.kill(pid, 9)
> 
> 9 is signal.SIGKILL.
> 15 is signal.SIGTERM.
> Maybe SIGTERM is better?

Not sure, looking at the FF bug when the process is hanging.
Comment 13 Eduard Mai univentionstaff 2016-04-18 14:00:46 CEST
Firefox does exit for me on SIGTERM in this particular case. However SIGKILL seems fine to me, as system-setup does not rely on Firefox exiting gracefully.
Comment 14 Alexander Kläser univentionstaff 2016-07-08 17:36:06 CEST
Changes: OK, works like a charm.
YAML: OK

→ VERIFIED
Comment 15 Janek Walkenhorst univentionstaff 2016-08-03 15:56:46 CEST
<http://errata.software-univention.de/ucs/4.1/234.html>