xilun / cbwin

Launch Windows programs from "Bash on Ubuntu on Windows" (WSL)
Other
327 stars 25 forks source link

find a workaround to mitigate failures of GetExtendedTcpTable() #17

Open xilun opened 8 years ago

xilun commented 8 years ago

GetExtendedTcpTable() sometimes miserably fails and returns 0xc0000001 (NT status generic error) (This prevents a command from being launched when this occurs.)

I must find a workaround to mitigate the effect of such failures. Calling GetExtendedTcpTable() again in a loop in this case is not efficient enough (I still have some failures after 5 retries...)

xilun commented 8 years ago

8ca3301 improves the reliability a lot.

It actually mainly do retry in a loop (for at most 5 times) but it seems that failures might be more common when launching cygwin processes and/or launching outbash.exe from within VS IDE. Also it comes with exp increase of buffer size (to amortize worst case complexity) and a buffer size of 8 extra bytes (as in the SIZEOF_TCPTABLE_OWNER_PID macro of the SDK)

I did some other attempts with other or less changes, and they did not work. (It was: avoiding reentrancy of GetExtendedTcpTable() with a mutex at various levels, only 8 extra bytes for alloc, and only using exp increase of buffer size.)

When tested in standalone (launched without VS IDE) in a loop with four client caller threads each launching 200 non-cygwin processes as fast as possible, 9 seconds of relaxation, tasklist and taskkill, keeping the test running for dozens of hours, I was not able to get a single 0xc0000001 failure not mitigated by the retry loop in version 8ca3301 -- even when trying to also simultaneously load the system by other means.

So I ship this mitigation. I keep this issue open for now for ref; the error message in case the mitigation is not enough is: outbash: CConnection::run() exception: GetExtendedTcpTable: unknown error