CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
80 stars 16 forks source link

Connecting to API is failing with a time-out #34

Closed stjohann closed 6 years ago

stjohann commented 6 years ago

Firstly, thank you for writing this library.

Today my Discord bot started failing to link [[wiki links]] with their respective articles. In the code I use this library (v. 0.5.1). The cause of this, as I understand after running testing versions, is because of a time-out from Site.CreateAsync.

I’ve tried to update the library to last pre-release version internally, but this error is still appearing and I don’t understand the cause. The error wasn’t present before today and Wikipedia API (specifically ru.wikipedia.org) seems to work fine. The stack trace for both versions is nearly the same, but I’ll publish it here for the convenience.

Sorry in advance if I am wasting your time and the error is on my side and not in the library.

0.5.1:

System.AggregateException was unhandled
  HResult=-2146233088
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at DiscordWikiBot.Linking.Init() in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Linking.cs:line 37
       at DiscordWikiBot.Program.<Run>d__8.MoveNext() in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Program.cs:line 71
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at DiscordWikiBot.Program.Main(String[] args) in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Program.cs:line 27
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233083
       Message=The operation has timed out.
       Source=WikiClientLibrary
       StackTrace:
            at WikiClientLibrary.Client.WikiClient.<SendAsync>d__0.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Client.WikiClient.<GetJsonAsync>d__19.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Site.<PostValuesAsync>d__44.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Site.<RefreshSiteInfoAsync>d__16.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Site.<CreateAsync>d__13.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
            at DiscordWikiBot.Linking.<FetchSiteInfo>d__8.MoveNext() in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Linking.cs:line 215
       InnerException: 

0.6-int6:

System.AggregateException was unhandled
  HResult=-2146233088
  Message=One or more errors occurred.
  StackTrace:
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at DiscordWikiBot.Linking.Init() in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Linking.cs:line 38
       at DiscordWikiBot.Program.<Run>d__8.MoveNext() in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Program.cs:line 71
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at DiscordWikiBot.Program.Main(String[] args) in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Program.cs:line 27
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233083
       Message=The operation has timed out.
       StackTrace:
            at WikiClientLibrary.Client.WikiClient.<SendAsync>d__38`1.MoveNext()
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Client.WikiClient.<InvokeAsync>d__35`1.MoveNext()
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
            at WikiClientLibrary.Sites.WikiSite.<InvokeMediaWikiApiAsync>d__47`1.MoveNext()
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Sites.WikiSite.<RefreshSiteInfoAsync>d__21.MoveNext()
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at WikiClientLibrary.Sites.WikiSite.<>c__DisplayClass20_0.<<-ctor>g__InitializeAsync|1>d.MoveNext()
            at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
            at DiscordWikiBot.Linking.<FetchSiteInfo>d__8.MoveNext() in C:\Users\####\documents\visual studio 2015\Projects\DiscordWikiBot\DiscordWikiBot\Linking.cs:line 217
       InnerException: 
CXuesong commented 6 years ago

First of all, I suggest you always to use the latest pre-release (that is, v0.6.0-intX6 up till now) because there are some major API changes involved since v0.5.

From the exception description, I suppose there is a time-out happening, so you might want to set WikiClient.Timeout to a slightly larger value (e.g. 1 minute) and try again.

Finally, you may set WikiClient.Logger to an ILogger implementation (you may reference Microsoft.Extensions.Logging.Console NuGet package, and use ConsoleLogger, for example), and see what happens exactly. If you have trouble setting up the logger, feel free to leave me a message here.

stjohann commented 6 years ago

Sorry for not answering for so long, I found that the problem was local so there nothing to fix in the library. Thank you for your assistance.