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 757088 - Hang when IMAP network connection is lost
Hang when IMAP network connection is lost
Status: RESOLVED FIXED
Product: geary
Classification: Other
Component: engine
master
Other Linux
: Normal major
: 0.11.0
Assigned To: Geary Maintainers
Geary Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-10-25 12:15 UTC by Michael Gratton
Modified: 2016-04-21 02:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Lazily enable graceful-disconnect (2.49 KB, application/mbox)
2015-10-25 12:46 UTC, Michael Gratton
  Details
Lazily enable graceful-disconnect (2.49 KB, patch)
2015-10-25 12:48 UTC, Michael Gratton
none Details | Review
Remove the TCP graceful disconnect implementation. (8.19 KB, patch)
2016-04-20 06:13 UTC, Michael Gratton
none Details | Review

Description Michael Gratton 2015-10-25 12:15:27 UTC
Geary master reliably hangs (i.e. 100% of the time) when connections to my Cyrus 2.4 server w/ StartTLS are lost without the server closing it. For whatever reason this seems to happen nearly all the time, so I find Geary hanging after a few minutes of inactivity 100% of the time after opening it.

The problem seems to arise since src/mailer/main.vala enables graceful disconnects for IMAP endpoints by default, causing Geary.Endpoint.connect_async to enable graceful disconnects for GTcpConnection instances immediately after they have been opened. Thus, when the open connection dies GTcpConnection attempts a graceful disconnects but hangs waiting for data from the server.

Here's the last relevant output when hang occurs with -d --log-deserializer enabled:

> [deb] 23:01:05 101.254822 imap-deserializer.vala:809: [des:0011/GEARY_IMAP_DESERIALIZER_STATE_TAG] input error: Socket I/O timed out
> [deb] 23:01:05 0.000021 imap-client-session.vala:1610: [000B/mail.quuxo.net/default:143 GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED] Receive failed: Socket I/O timed out
> [deb] 23:01:05 0.000004 imap-client-session.vala:1323: [000B/mail.quuxo.net/default:143 GEARY_IMAP_CLIENT_SESSION_STATE_AUTHORIZED] Receive error, disconnecting: Socket I/O timed out
> [deb] 23:01:05 0.000024 imap-deserializer.vala:250: [des:0011/GEARY_IMAP_DESERIALIZER_STATE_TAG] Waiting for deserializer to close...

Nothing further is printed after this.

This is the gdb stack trace at the same time:

  • #0 poll
    at ../sysdeps/unix/syscall-template.S line 81
  • #1 g_poll
    at /usr/include/x86_64-linux-gnu/bits/poll2.h line 46
  • #2 g_poll
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gpoll.c line 124
  • #3 g_socket_condition_timed_wait
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/gsocket.c line 3675
  • #4 g_socket_receive_with_blocking
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/gsocket.c line 2648
  • #5 g_tcp_connection_close
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/gtcpconnection.c line 168
  • #6 g_io_stream_close
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/giostream.c line 400
  • #7 0x00007fff704e9f15 in
  • #8 g_io_stream_close
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/giostream.c line 400
  • #9 g_io_stream_dispose
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/giostream.c line 101
  • #10 g_object_unref
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gobject/gobject.c line 3142
  • #11 0x00007fff704e8c5d in
  • #12 g_source_unref_internal
  • #13 g_child_source_remove_internal
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gmain.c line 1460
  • #14 g_source_destroy_internal
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gmain.c line 1225
  • #15 g_main_context_dispatch
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gmain.c line 3177
  • #16 g_main_context_dispatch
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gmain.c line 3769
  • #17 g_main_context_iterate
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gmain.c line 3840
  • #18 g_main_context_iteration
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./glib/gmain.c line 3901
  • #19 g_application_run
    at /build/glib2.0-ajuDY6/glib2.0-2.46.1/./gio/gapplication.c line 2311
  • #20 _vala_main
  • #21 __libc_start_main
    at libc-start.c line 289
  • #22 _start

Note that a mainloop source is being destroyed and the connection is getting unref'ed, hence Geary isn't explicitly closing it, but because graceful shutdown was enabled for it this is attempted, but hangs because the connection is already down. This might be a GLib bug.

A work-around is to avoid enabling graceful disconnects in Geary.Endpoint.connect_async, then in Geary.Imap.ClientConnection.disconnect_async enable graceful disconnect just before closing the GTcpConnection, but only if the stream reports itself as actually being open.
Comment 1 Michael Gratton 2015-10-25 12:26:25 UTC
Possible GLib bug filed as Bug 757091.
Comment 2 Michael Gratton 2015-10-25 12:46:42 UTC
Created attachment 314065 [details]
Lazily enable graceful-disconnect

Patch containing work-around for the problem.
Comment 3 Michael Gratton 2015-10-25 12:48:04 UTC
Created attachment 314066 [details] [review]
Lazily enable graceful-disconnect

Patch containing work-around for the problem (this time flagged as a patch).
Comment 4 Dan Winship 2015-10-27 14:03:00 UTC
Note that GTcpConnection:graceful-disconnect is not useful for IMAP connections anyway, since it is already handled at the IMAP protocol level; the client sends LOGOUT and then waits for the OK response from the server.
Comment 5 Michael Gratton 2016-04-20 05:25:48 UTC
See also Bug 765287.
Comment 6 Michael Gratton 2016-04-20 06:13:50 UTC
Created attachment 326377 [details] [review]
Remove the TCP graceful disconnect implementation.

Since both IMAP and SMTP implement graceful disconnect at the application protocol level, doing it again at the TCP level is redundant.
    
The use of graceful disconnect was introduced as part of the fix for Bug 713736, but it is not clear why it was included. Removing it also fixes Bug 757088, which can cause the UI to freeze if the connection is lost (e.g. on wifi drop out).
Comment 7 Michael Gratton 2016-04-20 06:16:14 UTC
(In reply to Dan Winship from comment #4)
> Note that GTcpConnection:graceful-disconnect is not useful for IMAP
> connections anyway, since it is already handled at the IMAP protocol level;
> the client sends LOGOUT and then waits for the OK response from the server.

Yeah, good point - same for SMTP. Updated patch just removes it altogether. It might still be nice to fix the root cause of the freeze in Bug 757091.
Comment 8 Michael Gratton 2016-04-20 06:18:55 UTC
Adam: I haven't run the updated patch much at all, but the effect is the same as the original patch, and I've been running that as part of my local build for the last 6 months with out any issue. I think it would be worth while committing.
Comment 9 Adam Dingle 2016-04-20 09:45:53 UTC
Pushed to master.

I've also seen this hang often, so it will be great news if this fixes it.  Marking as fixed, optimistically.