4

Retrofit 2.0.0 を使用しています。OkHttp 3.1.2。一部のユーザーが次の例外を受け取ります。

java.net.SocketException: ソケットが失敗しました: libcore.io.IoBridge.socket(IoBridge.java:619) の EMFILE (開いているファイルが多すぎます) ~[na:0.0] java.net.PlainSocketImpl.create(PlainSocketImpl.java: 198) ~[na:0.0] at java.net.Socket.checkOpenAndCreate(Socket.java:689) ~[na:0.0] at java.net.Socket.setSoTimeout(Socket.java:543) ~[na:0.0] com.android.org.conscrypt.OpenSSLSocketImpl.setSoTimeout(OpenSSLSocketImpl.java:1140) で ~[na:0.0] com.android.org.conscrypt.OpenSSLSocketImplWrapper.setSoTimeout(OpenSSLSocketImplWrapper.java:111) で ~[na:0.0] okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:155) で ~[na:0.0] okhttp3.internal.io.RealConnection.connect(RealConnection.java:111) で ~[na:0.0] okhttp3.internal で.http.StreamAllocation.findConnection(StreamAllocation.java:188) ~[na:0.0] okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127) で ~[na:0.0] okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) で ~[na:0.0] okhttp3 で.internal.http.HttpEngine.connect(HttpEngine.java:289) ~[na:0.0] で okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241) ~[na:0.0] okhttp3.RealCall.getResponse で(RealCall.java:240) ~[na:0.0] で okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) ~[na:0.0]sendRequest(HttpEngine.java:241) ~[na:0.0] at okhttp3.RealCall.getResponse(RealCall.java:240) ~[na:0.0] at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) ~[ na:0.0]sendRequest(HttpEngine.java:241) ~[na:0.0] at okhttp3.RealCall.getResponse(RealCall.java:240) ~[na:0.0] at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) ~[ na:0.0]

crashlytics を見ると、実行中の多くのスレッドが表示されます。

com.android.org.conscrypt.NativeCrypto.SSL_read(NativeCrypto.java) で com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:811) で okio.Okio$2.read(Okio.java: 139) okio.AsyncTimeout$2.read(AsyncTimeout.java:211) で okio.RealBufferedSource.request(RealBufferedSource.java:71) で okio.RealBufferedSource.require(RealBufferedSource.java:64) で okio.RealBufferedSource.readInt(RealBufferedSource .java:232) で okhttp3.internal.framed.Spdy3$Reader.nextFrame(Spdy3.java:129) で okhttp3.internal.framed.FramedConnection$Reader.execute(FramedConnection.java:600) で okhttp3.internal.NamedRunnable で。 java.lang.Thread.run(Thread.java:818) で run(NamedRunnable.java:32)

この方法で、アプリで一度だけ Okhttp を開始しています。

OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
    clientBuilder.connectTimeout(3 * 1000, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(25 * 1000, TimeUnit.MILLISECONDS);

    File cacheDir = new File(mWeakContext.get().getFilesDir().getAbsolutePath(), "http-cache");
    Cache cache = new Cache(cacheDir, 16 * 1024 * 1024); // 16MB
    clientBuilder.cache(cache);

    // set proxy
    Properties properties = System.getProperties();
    if (properties.containsKey("https.proxyHost")) {

        String proxyHost = properties.getProperty("https.proxyHost");
        int proxyPort = Integer.parseInt(properties.getProperty("https.proxyPort"));

        clientBuilder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
                proxyHost,
                proxyPort)
        ));
    }
    clientBuilder.addInterceptor(mHeadersInterceptor);
    clientBuilder.addInterceptor(mSignInterceptor);
    clientBuilder.addInterceptor(mLoggingInterceptor);
    mClient = clientBuilder.build();

それはあまり起こらず、自分のデバイスで再現できないので、ここではかなり無知です。

4

0 に答える 0