Force create SocketImpl in test_connectLjava_net_SocketAddressI_setSOTimeout.

Prevents unsynchronized race between two threads to create it later
which end up attempting to set the FileDescriptor owner twice.

Tested by adding sleeps to one code path to force the race to occur
100% when running
OldSocketTest.test_connectLjava_net_SocketAddressI_setSOTimeout() and
verifiying the test passes again with this change.

This also explains and should fix the resource leakage noted in an older bug.

Bug: 31820278
Fixes: 144258500
Test: See above.
Change-Id: I8814bbe19aee0bad80106cdb8eb468a81d8071b2
(cherry picked from commit 2b55dc7947d341b571a2a26654e2907af8e1a35d)
diff --git a/luni/src/test/java/libcore/java/net/OldSocketTest.java b/luni/src/test/java/libcore/java/net/OldSocketTest.java
index f20f93d..644fe52 100644
--- a/luni/src/test/java/libcore/java/net/OldSocketTest.java
+++ b/luni/src/test/java/libcore/java/net/OldSocketTest.java
@@ -1269,9 +1269,6 @@
         }
     }
 
-    @DisableResourceLeakageDetection(
-            why = "Strange threading behavior causes resource leak",
-            bug = "31820278")
     public void test_connectLjava_net_SocketAddressI_setSOTimeout() throws Exception {
         final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
 
@@ -1298,6 +1295,9 @@
 
         // Now try to set options while we are connecting
         try (final Socket theSocket = new Socket()) {
+            // Force SocketImpl creation to prevent race between connect() and setSoTimeout()
+            // creating it. b/144258500
+            theSocket.getSoTimeout();
             final SocketConnector connector
                 = new SocketConnector(5000, theSocket, UNREACHABLE_ADDRESS);
             connector.start();