[Galaxy S 4 Mini Android Development] coldgin_:
Hi !

what I see is that you are right :) first time trying to connect fails, and immediately does fine. Look (I'm marking in bold the important lines):

08-13 00:23:54.079 D/wpa_supplicant( 921): RX ctrl_iface - hexdump(len=11): 53 49 47 4e 41 4c 5f 50 4f 4c 4c
08-13 00:23:54.079 D/wpa_supplicant( 921): wlan0: Control interface command 'SIGNAL_POLL'
08-13 00:23:54.079 D/wpa_supplicant( 921): [B]nl80211: survey data missing![/B]
08-13 00:23:54.100 D/AndroidRuntime(18867): Calling main entry com.android.commands.am.Am
08-13 00:23:54.120 D/wpa_supplicant( 921): RX ctrl_iface - hexdump(len=14): 53 43 41 4e 20 54 59 50 45 3d 4f 4e 4c 59
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: Control interface command 'SCAN TYPE=ONLY'
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: Setting scan request: 0 sec 0 usec
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: Starting AP scan for wildcard SSID
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: nl80211: scan request
08-13 00:23:54.120 D/wpa_supplicant( 921): [B]nl80211: Scan SSID - hexdump(len=0): [NULL][/B]
08-13 00:23:54.120 D/wpa_supplicant( 921): [B]Scan requested (ret=0) - scan timeout 30 seconds[/B]
08-13 00:23:54.120 D/wpa_supplicant( 921): nl80211: Event message available
08-13 00:23:54.120 D/wpa_supplicant( 921): nl80211: Drv Event 33 (NL80211_CMD_TRIGGER_SCAN) received for wlan0
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: nl80211: Scan trigger
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: Event SCAN_STARTED (57) received
08-13 00:23:54.120 D/wpa_supplicant( 921): wlan0: Own scan request started a scan
08-13 00:23:54.120 I/wpa_supplicant( 921): wlan0: CTRL-EVENT-SCAN-STARTED

....
08-13 00:23:54.510 D/dalvikvm(18885): Trying to load lib libjavacore.so 0x0
08-13 00:23:54.510 D/dalvikvm(18885): Added shared lib libjavacore.so 0x0
08-13 00:23:54.550 D/dalvikvm(18885): Note: class Landroid/app/ActivityManagerNative; has 180 unimplemented (abstract) methods
08-13 00:23:54.550 D/su (18899): 10173 /system/xbin/su executing 0 /system/bin/sh using binary /system/bin/sh : sh
08-13 00:23:54.730 D/wpa_supplicant( 921):[B] nl80211: Event message available[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921): [B]nl80211: Drv Event 34 (NL80211_CMD_NEW_SCAN_RESULTS) received for wlan0[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921): [B]wlan0: nl80211: New scan results available[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921): [B]wlan0: Event SCAN_RESULTS (3) received[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921): [B]nl80211: Associated on 2462 MHz[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921):[B] nl80211: Associated with 08:96:d7:1a:18:b0[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921):[B] nl80211: Received scan results (8 BSSes)[/B]
08-13 00:23:54.730 D/wpa_supplicant( 921): nl80211: Survey data missing
08-13 00:23:54.730 D/wpa_supplicant( 921): nl80211: Scan results indicate BSS status with 08:96:d7:1a:18:b0 as associated
08-13 00:23:54.730 D/wpa_supplicant( 921): Sorted scan results
08-13 00:23:54.730 D/wpa_supplicant( 921): [B]9c:80:df:52:2e:58 freq=2417 qual=0 noise=0 level=-60 flags=0xb age=0[/B]

What is happening here is evident, your phone cannot find any router because the wifi module (at linux level) is failling at start.

Why? Dunno !! :( But what I can see in other lines of this log is that maybe (and just maybe) MP-Decision is involved. Try using another hotplug, like Intelli-plug or msm-plug. And please give me all the info about your using of UV, UC / OC, the governor you are using, the scheduler and the read_ahead_buffer. And any other info you consider convenient for me to know,e.g: modem version, etc

This seems to be a problem related to your configuration, and not a generic one. But we will see !!

Send me this info and I will try to make my system fails this way and look for a solution :fingers-crossed:

Edit: Do you have more than one AP (access point) with the same SSID in the place where you are suffering this issue? If yes, maybe it's related to a known android bug....

Regards !