Skip to content

Commit bcbe19e

Browse files
cortinicometa-codesync[bot]
authored andcommitted
WebSocketModule uses OkHttpClientProvider (facebook#55885)
Summary: Pull Request resolved: facebook#55885 Instead of creating a brand-new OkHttpClient.Builder() per WebSocket connection, derive from OkHttpClientProvider.getOkHttpClient() so that all connections share the same connection pool and dispatcher. Also remove the dispatcher shutdown call, since the dispatcher is now shared with the global OkHttpClient and shutting it down would kill all connections. Changelog: [Internal] Reviewed By: cipolleschi, javache Differential Revision: D95059116
1 parent a934087 commit bcbe19e

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.facebook.react.common.ReactConstants
2222
import com.facebook.react.module.annotations.ReactModule
2323
import com.facebook.react.modules.network.CustomClientBuilder
2424
import com.facebook.react.modules.network.ForwardingCookieHandler
25+
import com.facebook.react.modules.network.OkHttpClientProvider
2526
import java.io.IOException
2627
import java.net.URI
2728
import java.net.URISyntaxException
@@ -80,7 +81,8 @@ public class WebSocketModule(context: ReactApplicationContext) :
8081
) {
8182
val id = socketID.toInt()
8283
val okHttpBuilder =
83-
OkHttpClient.Builder()
84+
OkHttpClientProvider.getOkHttpClient()
85+
.newBuilder()
8486
.connectTimeout(10, TimeUnit.SECONDS)
8587
.writeTimeout(10, TimeUnit.SECONDS)
8688
.readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read
@@ -198,9 +200,6 @@ public class WebSocketModule(context: ReactApplicationContext) :
198200
}
199201
},
200202
)
201-
202-
// Trigger shutdown of the dispatcher's executor so this process can exit cleanly
203-
client.dispatcher().executorService().shutdown()
204203
}
205204

206205
override fun close(code: Double, reason: String?, socketID: Double) {

0 commit comments

Comments
 (0)