[geary/wip/ubuntu-1804-network-unreachable] Retry using IPv4 only when connecting to an endpoint fails



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

    Retry using IPv4 only when connecting to an endpoint fails
    
    Ubuntu 18.04 for some reason started throwing "Address family not
    supported by protocol" 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..1ddd76ca 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.NOT_SUPPORTED err) {
+            connect_error = err;
+        }
+
+        // Ubuntu 18.04 for some reason started throwing NOT_SUPPORTED
+        // 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]