[geary/wip/ubuntu-1610-network-unreachable: 2/2] Retry using IPv4 only when connecting to an endpoint



commit 4676b3e82ecf89c45d050199d82526a8ff58a8cc
Author: Michael Gratton <mike vee net>
Date:   Mon Feb 18 22:42:11 2019 +1100

    Retry using IPv4 only when connecting to an endpoint
    
    Ubuntu 18.04 for some reason started throwing network unavailable
    errors when an AAAA record was resolved for host name but no valid
    IPv6 network was available. Work around by re-attempting once using
    IPv4 only.
    
    See issue #217.

 src/engine/api/geary-endpoint.vala | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/engine/api/geary-endpoint.vala b/src/engine/api/geary-endpoint.vala
index 4968751a..e408c1b3 100644
--- a/src/engine/api/geary-endpoint.vala
+++ b/src/engine/api/geary-endpoint.vala
@@ -119,8 +119,28 @@ public class Geary.Endpoint : BaseObject {
         this.tls_method = method;
     }
 
-    public async SocketConnection connect_async(Cancellable? cancellable = null) throws Error {
-        return yield get_socket_client().connect_async(this.remote, cancellable);
+    public async GLib.SocketConnection connect_async(GLib.Cancellable? cancellable = null)
+        throws GLib.Error {
+        GLib.SocketClient client = get_socket_client();
+        GLib.IOError? connect_error = null;
+        try {
+            return yield client.connect_async(this.remote, cancellable);
+        } catch (GLib.IOError.NETWORK_UNREACHABLE err) {
+            connect_error = err;
+        }
+
+        // Ubuntu 18.04 for some reason started throwing these errors
+        // when an AAAA record was resolved for host name but no valid
+        // IPv6 network was available. Work around by re-attempting
+        // once using IPv4 only. See issue #217.
+        client.family = GLib.SocketFamily.IPV4;
+        try {
+            return yield client.connect_async(this.remote, cancellable);
+        } catch (GLib.Error err) {
+            debug("Connect error while working around network unavailable: %s",
+                  err.message);
+            throw connect_error;
+        }
     }
 
     public async TlsClientConnection starttls_handshake_async(IOStream base_stream,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]