choosenim icon indicating copy to clipboard operation
choosenim copied to clipboard

`choosenim dir` stuck forever in analytics when network connection drops, no simple workaround

Open timotheecour opened this issue 4 years ago • 1 comments

choosenim dir stuck forever in analytics when network connection drops

I reproduced this a few times. There should be some kind of timeout to avoid this (IIRC there was a 5s timeout in place, but doesnt' seem to work, I interrupted after 20 seconds by ^C)

choosenim $dir
^CTraceback (most recent call last)
/Users/timothee/git_clone/nim/choosenim/src/choosenim.nim(267) choosenim
/Users/timothee/git_clone/nim/choosenim/src/choosenim.nim(238) performAction
/Users/timothee/git_clone/nim/choosenim/src/choosenimpkg/telemetry.nim(164) report
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) reportEvent
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) reportEventNimAsyncContinue
/Users/timothee/.nimble/pkgs/analytics-0.2.0/analytics.nim(94) reportEventIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) postContent
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) postContentNimAsyncContinue
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/httpclient.nim(1004) postContentIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) post
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) postNimAsyncContinue
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/httpclient.nim(997) postIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) request
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) requestNimAsyncContinue
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/httpclient.nim(907) requestIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) requestAux
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) requestAuxNimAsyncContinue
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/httpclient.nim(876) requestAuxIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) newConnection
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) newConnectionNimAsyncContinue
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/httpclient.nim(810) newConnectionIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(313) dial
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncmacro.nim(34) dialNimAsyncContinue
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncnet.nim(272) dialIter
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/asyncdispatch.nim(1765) dial
/Users/timothee/.choosenim/toolchains/nim-1.0.4/lib/pure/nativesockets.nim(261) getAddrInfo
SIGINT: Interrupted by Ctrl-C.

choosenim -v choosenim v0.5.0 (2020-01-14 23:56:52) [macosx/amd64]

workaround

create a hotspot using your phone, connect internet to that, then it works; note that if i stop my network connection after that and rerun choosenim $dir, no more hang, but I presume it's because analytics were already collected in some recent time

timotheecour avatar Mar 03 '20 09:03 timotheecour

Probably updating analytics.nim#newAnalyticsRef:43 with default timeout

      when T is HttpClient: newHttpClient(userAgent = ua, proxy = proxy, timeout = connectionTimeoutMs)
      else: newAsyncHttpClient(userAgent = ua, proxy = proxy, timeout = connectionTimeoutMs),

could've helped. But currently Nim's sync http client supports timeout parameter, while async client does not (there is a todo there, httpclient.nim#newAsyncHttpClient).

Seems like choosenim generally relies on async analytics, which uses async http client, so above mentioned patch won't help :)

Maybe this little comment will help someone in future to fix the issue

romanthekat avatar Oct 31 '20 15:10 romanthekat