pyamsoft / tetherfi

TetherFi - Internet sharing without Root
Apache License 2.0
386 stars 29 forks source link

Unable to start hotspot - Invalid argument #258

Closed Programmerino closed 7 months ago

Programmerino commented 8 months ago

Device: Pixel 6a on Android 14 Issue: Regardless of the port, name, or password chosen, the following error occurs after any device attempts to connect to the hotspot. I've also noticed that the NetShare application which appears to use the same WiFi Direct legacy group + proxy strategy also mysteriously stops after starting. Logs:

[D] Resetting network Status 
[D] Proxy Status Changed: NotRunning 
[D] Starting Proxy... 
[D] Start Foreground Service! 
[D] Creating service 
[D] Starting runner! 
[D] Starting Proxy! 
[D] Start WiDi Network 
[D] #################################### 
[D] Acquire CPU wakelock: com.pyamsoft.tetherfi:PROXY_WAKE_LOCK 
[D] #################################### 
[D] Started foreground notification: NotifyId(id=42069): ServerNotificationData(status=NotRunning, clientCount=0, blockCount=0) 
[D] #################################### 
[D] Acquire WiFi wakelock: com.pyamsoft.tetherfi:PROXY_WIFI_LOCK 
[D] #################################### 
[D] Starting Wifi Network... 
[D] START NEW NETWORK 
[D] WiDi Status Changed: Starting 
[D] Starting broadcast network 
[D] Creating WifiP2PManager Channel 
[D] Updated foreground notification: NotifyId(id=42069): ServerNotificationData(status=Starting, clientCount=0, blockCount=0) 
[D] Attempt open connection with channel 
[D] Cannot re-use Wi-Fi group connection, make new one 
[D] Creating new wifi p2p group 
[D] New network created 
[D] New Wi-Fi group connection created! 
[D] Network started, store data source: android.net.wifi.p2p.WifiP2pManager$Channel@e10a97 
[D] Network update Group=Connected(ssid=DIRECT-TF-Davis, password=xxx) 
[D] Network update Connection=Connected(hostName=192.168.49.1) 
[D] Track new proxy job! 
[D] Wifi Direct is fully set up! 
[D] Clear client tracker 
[D] WiDi Status Changed: Running 
[D] Register Wifi Receiver 
[D] Hotspot was turned ON, refresh network settings to update 
[D] Attempt update network info with source android.net.wifi.p2p.WifiP2pManager$Channel@e10a97 
[D] Create a new cachedThreadPool dispatcher for Server 
[D] Limit Server CoroutineDispatcher n=(24) 
[D] Limit Server CoroutineDispatcher n=(2) 
[D] Starting proxy server ... 
[D] Proxy Status Changed: Starting 
[D] TCP Begin proxy server loop: Connected(hostName=192.168.49.1) 
[D] Watch client count and shutdown if none 
[D] In app rating check: {lastVersion=0, isAlreadyShown=false, hotspotUsed=5, devicesConnected=0, appOpened=6} 
[D] Bind TCP server to local address: /192.168.49.1:65000 
[D] Proxy has fully launched, update status! 
[D] Proxy Status Changed: Running 
[D] Awaiting TCP connections on /192.168.49.1:65000 
[D] Updated foreground notification: NotifyId(id=42069): ServerNotificationData(status=Running, clientCount=0, blockCount=0) 
[D] WiFi Direct: Enabled 
[D] Attempt update network info with source android.net.wifi.p2p.WifiP2pManager$Channel@e10a97 
[D] Attempt update network info with source android.net.wifi.p2p.WifiP2pManager$Channel@e10a97 
[E] Error running server loop: TCP
java.io.IOException: Invalid argument
    at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
    at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
    at io.ktor.network.sockets.ServerSocketImpl.acceptSuspend(SourceFile:76)
    at io.ktor.network.sockets.ServerSocketImpl$acceptSuspend$1.invokeSuspend(SourceFile:12)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:9)
    at kotlinx.coroutines.DispatchedTask.run(SourceFile:113)
    at androidx.fragment.app.Fragment$3.run(SourceFile:78)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
    at java.lang.Thread.run(Thread.java:1012)
 Invalid argument
[D] Shutdown Primary Dispatcher 
[D] Shutdown SideEffect Dispatcher 
[D] Clear client tracker 
[D] Stopping timer flow 10m 
[D] Proxy Status Changed: ProxyError(throwable=java.io.IOException: Invalid argument) 
[D] Shutdown event received! 
[D] Shutdown event received! 
[D] Stop Foreground Service! 
[D] Destroying service 
[D] Stopped Proxy Server 
[D] Shutting down proxy... 
[D] Shutdown Primary Dispatcher 
[D] Shutdown SideEffect Dispatcher 
[D] Clear client tracker 
[D] Proxy Server is Done! 
[D] WiFi Direct: Disabled 
[D] Stop foreground notification 
[D] Unregister Wifi Receiver 
[D] Stopping Wifi Network... 
[D] STOP NETWORK 
[D] Shutting down network 
[D] Hotspot was turned OFF, refresh network settings to clear 
[D] Stopped proxy job 
[D] Stop broadcast server source 
[D] WiDi Status Changed: Stopping 
[D] Stop existing WiFi Group 
[D] Page swiped: CONNECTIONS 
[W] Failed to stop network: Busy 
[D] Close Group failed but continue teardown anyway 
[D] Close WiFiP2PManager channel 
[D] Reset last info refresh times 
[D] Network was stopped 
[D] Attempt update network info with source null 
[W] Cannot get group info without Wifi source 
[W] Cannot get connection info without Wifi source 
[D] #################################### 
[D] Release CPU wakelock: com.pyamsoft.tetherfi:PROXY_WAKE_LOCK 
[D] #################################### 
[D] #################################### 
[D] Release WIFI wakelock: com.pyamsoft.tetherfi:PROXY_WIFI_LOCK 
[D] #################################### 
[D] WifiP2PManager Channel died! Do nothing :D 
[D] Stopping runner! 
[D] Page swiped: INFO 
[D] WiDi Status Changed: NotRunning 
[D] Proxy Status Changed: ProxyError(throwable=java.io.IOException: Invalid argument) 
[D] Attempt update network info with source null 
[W] Cannot get group info without Wifi source 
[W] Cannot get connection info without Wifi source 
pyamsoft commented 8 months ago

Hi, use a lower port number instead of 65000. Try the default of 8228?

Please also attach a screenshot of your Hotspot screen, thanks!

Programmerino commented 8 months ago

I was testing the issue with a range of ports to see if it changed anything, here's the issue with default settings: Screenshot_20231226-135451.png

pyamsoft commented 8 months ago

Ok cool thanks. Something seems to be causing problems for the ktor socket we use. I wonder if they know anything. Thsnks for the report, I'll dig around

pyamsoft commented 8 months ago

Hi, I've looked into this and it seems like an IOException is unique to a device given a specific situation.

Basically its a tough bug. That being said, it looks like our ktor library can handle this by just "ignoring" the error and continuing to try again and again.

The next version will have a new experimental tweak called "Stubborn Proxy" which will ignore the error and keep trying, as well as some other tweaks to how we establish the server.

While I don't have a release date in mind yet, I hope when this new release comes out it may be able to help the problem, or further isolate the cause. Hopefully in the next few weeks.

Thanks!

pyamsoft commented 8 months ago

Hello

Version 40 is recently released on the play store. Please download it when you have the chance and try enabling the "Stubborn Proxy" tweak. Thanks!

Programmerino commented 7 months ago

When I initially tested this change, it didn't seem to be working, but when I was trying to collect logs to submit here now everything seems to be working as expected! I'll keep you updated if anything changes. Thank you!