GNOME Bugzilla – Bug 424207
printing hangs on unreachable cups server
Last modified: 2008-11-13 21:56:46 UTC
If the cups server is unreachable then gtk_print_operation_run hangs. See bug 424041
note that this is somewhat related to Bug 387889 since in both cases printing hangs at the same place. GTK should not depend on immediate completion. But show the print dialog anyways. It could add printers as they become available.
What I am seeing is that we are blocking in connect(). The cups libraries don't allow to do a non-blocking connect...
I think I can confirm this behaviour, with some small additional information. I have gtk+, 2.10.13 on a gentoo linux machine, 32bit. When running gtk-demo (I think this should be a minimal example) and double-click the "Printing" entry, and either cupsd is not running or the printing server is not responding or running, it _seems_ as if gtk-demo was completely frozen. But after some time (approx. 2 minutes) the Gtk print dialog window appears, though none of its widgets are drawn, it then seems to be just as frozen as thegtk-demo window. If anyone needs the configure output, I'll attach it. I could no reproduce this on Kubuntu 7.04 though (2.10.11 standard install there).
See also http://bugs.debian.org/448623. It is a known issue that CUPS libraries don't have a non-blocking API, but wouldn't it be possible to split these calls in a separate thread?
Created attachment 114779 [details] [review] a patch to handle unreachable cups server state Hi, this patch change calling of cups_request_default_printer(). The cups_request_default_printer() is called in regular intervals. In the case of failed connection it tries to connect at next 10 seconds. It freezes dialog for a few seconds in each attempt but it doesn't need other thread. Marek
Would be nicer to use a timeout_add_seconds variants for such a long timeout, but I guess we don't have a gdk_threads variant of that (yet)... + /* A test whether it is possible to connect to a CUPS server. + * If the connection fails then we return TRUE to repeat calling + * of this function later. + */ Not sure I understand this part. Does httpConnectEncrypt() return NULL without blocking, if the server is unreachable ?
Hi, the function httpConnectEncrypt() is blocking, but it is not called continually with this patch. It gives a time to the dialog to refresh. I didn't find any non-blocking test of connection with CUPS (1.3.x) in libraries linked to GTK+. Marek
Hi, I'm implementing the testing of reachability of CUPS server using non-blocking connect(), not using CUPS functions (thanks to Tim Waugh for his suggestion). It works somehow. I'll upload a patch soon (I hope). Regards Marek
Created attachment 115012 [details] [review] a patch to handle unreachable cups server state in non-blocking manner This patch test connection to CUPS server before calling of the first httpConnectEncrypt() (in one of functions called in gtk_print_backend_cups_init() ). The test is non-blocking, implemented using connect() with O_NONBLOCK flag. If the server is unreachable then the test is performed each second until the server is reachable. However, this patch doesn't solve the case when the connection is lost during run of the GtkPrintDialog(). Marek
Created attachment 115014 [details] [review] previous patch with new function gdk_threads_add_timeout_seconds() This is previous patch with functions gdk_threads_add_timeout_seconds() and gdk_threads_add_timeout_seconds_full() added. Marek
I think it might be nicer to move the nonblocking check to a separate is_cups_server_available function in gtkcupsutils.c. What do you think ?
Hi Matthias, it looks nicer. I'll change it accordingly. Marek
Created attachment 115552 [details] [review] reworked patch Hi all, this is reworked patch. There is new structure GtkCupsConnectionTest to which I store address and actual socket for new connection. There are also 3 new functions for allocation, freeing and checking of connection to CUPS server. Marek
Thanks for the new patch. Some more comments: 1) please split the timeout_add_seconds additions off in a separate patch. (We'll have to plead with the gnome release team for api additions at this point...) 2) I think the docs for gdk_threads_add_timeout_seconds_full shouldn't repeat all the details, and just say: For details, see gdk_thread_add_timeout_full(). on to the cups stuff: 3) + /* The first call of cups_request_default_printer() initializes non-blocking test connection. + */ Would it not be possible to do the initialization in gtk_cups_connection_test_new ? Having to call it twice strikes me as unelegant... Other than this, it looks good to me.
Created attachment 115614 [details] [review] gdk_threads_add_timeout_seconds* functions added Hi, this patch adds gdk_threads_add_timeout_seconds* functions. Marek
Created attachment 115615 [details] [review] reworked patch This patch adds non-blocking testing of reachability of CUPS server. Initialization of first attempt to connect to specified CUPS server is done by gtk_cups_connection_test_new() function. This patch has to be committed after the patch "#115614: gdk_threads_add_timeout_seconds* functions added" because it uses new functions from the patch. Marek
2008-07-31 Matthias Clasen <mclasen@redhat.com> Bug 424207 – printing hangs on unreachable cups server * modules/printbackends/cups/gtkcupsutils.[hc]: Implement a non-blocking test for reachability of the cups server. * modules/printbackends/cups/gtkprintbackendcups.c: Don't block while trying to get the default printer. Patch by Marek Kasik.