From 4bb214cb2af6a10091438067202138ccc61aed59 Mon Sep 17 00:00:00 2001 From: AsamK Date: Sun, 31 Jan 2021 17:03:44 +0100 Subject: [PATCH] Configure keep alive duration for okhttp connection pool to 1 minute. The signal http server supports http keep alive, but closes idle connections after 1 minute. The default OkHttp connection pool will keep idle connections in the pool for 5 minutes and doesn't notice it when the server closes connections. As currently the automatic okhttp retries are disabled, reusing such a stale connection will be fatal. Issue is especially severe for incoming calls, which fail because the request to retrieve the turn servers fails and isn't retried: #10787 --- .../signalservice/internal/push/PushServiceSocket.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsignal/service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java b/libsignal/service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java index 79d5a6dcab..786abd6dd7 100644 --- a/libsignal/service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java +++ b/libsignal/service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java @@ -138,6 +138,7 @@ import javax.net.ssl.X509TrustManager; import okhttp3.Call; import okhttp3.Callback; +import okhttp3.ConnectionPool; import okhttp3.ConnectionSpec; import okhttp3.Credentials; import okhttp3.Dns; @@ -1807,6 +1808,8 @@ public class PushServiceSocket { .connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))) .build(); + builder.connectionPool(new ConnectionPool(5, 45, TimeUnit.SECONDS)); + for (Interceptor interceptor : interceptors) { builder.addInterceptor(interceptor); }