After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 424207 - printing hangs on unreachable cups server
printing hangs on unreachable cups server
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
unspecified
Other Linux
: Normal major
: ---
Assigned To: gtk-bugs
Depends on:
Blocks: 424041
 
 
Reported: 2007-03-29 18:05 UTC by Andreas J. Guelzow
Modified: 2008-11-13 21:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a patch to handle unreachable cups server state (5.81 KB, patch)
2008-07-18 15:49 UTC, Marek Kašík
none Details | Review
a patch to handle unreachable cups server state in non-blocking manner (7.58 KB, patch)
2008-07-22 15:05 UTC, Marek Kašík
none Details | Review
previous patch with new function gdk_threads_add_timeout_seconds() (15.38 KB, patch)
2008-07-22 15:10 UTC, Marek Kašík
none Details | Review
reworked patch (22.45 KB, patch)
2008-07-30 10:38 UTC, Marek Kašík
none Details | Review
gdk_threads_add_timeout_seconds* functions added (6.32 KB, patch)
2008-07-31 10:27 UTC, Marek Kašík
committed Details | Review
reworked patch (14.83 KB, patch)
2008-07-31 10:39 UTC, Marek Kašík
committed Details | Review

Description Andreas J. Guelzow 2007-03-29 18:05:49 UTC
If the cups server is unreachable then gtk_print_operation_run hangs. See bug 424041
Comment 1 Andreas J. Guelzow 2007-03-29 18:13:42 UTC
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.
Comment 2 Matthias Clasen 2007-04-29 23:16:37 UTC
What I am seeing is that we are blocking in connect(). 
The cups libraries don't allow to do a non-blocking connect...
Comment 3 quazgar 2007-07-29 13:54:14 UTC
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).
Comment 4 Josselin Mouette 2007-10-31 12:50:25 UTC
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?
Comment 5 Marek Kašík 2008-07-18 15:49:42 UTC
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
Comment 6 Matthias Clasen 2008-07-18 16:41:29 UTC
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 ?
Comment 7 Marek Kašík 2008-07-21 11:58:48 UTC
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
Comment 8 Marek Kašík 2008-07-21 16:50:02 UTC
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
Comment 9 Marek Kašík 2008-07-22 15:05:05 UTC
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
Comment 10 Marek Kašík 2008-07-22 15:10:20 UTC
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
Comment 11 Matthias Clasen 2008-07-22 15:38:18 UTC
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 ?
Comment 12 Marek Kašík 2008-07-22 16:08:56 UTC
Hi Matthias,
it looks nicer. I'll change it accordingly.

  Marek
Comment 13 Marek Kašík 2008-07-30 10:38:56 UTC
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
Comment 14 Matthias Clasen 2008-07-30 15:33:16 UTC
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.
Comment 15 Marek Kašík 2008-07-31 10:27:47 UTC
Created attachment 115614 [details] [review]
gdk_threads_add_timeout_seconds* functions added

Hi,
this patch adds gdk_threads_add_timeout_seconds* functions.

  Marek
Comment 16 Marek Kašík 2008-07-31 10:39:12 UTC
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
Comment 17 Matthias Clasen 2008-07-31 23:57:39 UTC
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.