discord-net / Discord.Net

An unofficial .Net wrapper for the Discord API (https://discord.com/)
https://discordnet.dev
MIT License
3.33k stars 736 forks source link

Discord.net 0.9.5 + Mono - An address incompatible with the requested protocol was used #297

Closed mzabsky closed 7 years ago

mzabsky commented 8 years ago

The bot works very well on my Windows machine, but when I tried to migrate it to a Linux server, it built fine, but when I start it, I get the following exception:

Log 10/2/2016 7:19:48 PM: GET voice/regions: 401.86 ms
Log 10/2/2016 7:19:48 PM: GET gateway: 22.95 ms
Log 10/2/2016 7:19:48 PM: Login successful, gateway: wss://gateway.discord.gg/?encoding=json&v=4
Crashed with exception, restarting.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used
  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x0005d] in <6c7c03f48a9747c8a644da4f63a34480>:0
  at System.Net.Sockets.Socket.ConnectAsync (System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e) [0x0000b] in <6c7c03f48a9747c8a644da4f63a34480>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00053] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at SuperSocket.ClientEngine.ConnectAsyncExtension.ConnectAsync (System.Net.EndPoint remoteEndPoint, SuperSocket.ClientEngine.ConnectedCallback callback, System.Object state) [0x00039] in <4ba236fbf29248a4985a92e6e3907e4a>:0
  at SuperSocket.ClientEngine.TcpClientSession.Connect () [0x00074] in <4ba236fbf29248a4985a92e6e3907e4a>:0
  at WebSocket4Net.WebSocket.Open () [0x0003a] in <4ba236fbf29248a4985a92e6e3907e4a>:0
  at Discord.Net.WebSockets.WS4NetEngine.Connect (System.String host, System.Threading.CancellationToken cancelToken) [0x000cc] in <599fbedd978e4fce934746a63a740a87>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at Discord.Net.WebSockets.WebSocket+<BeginConnect>d__34.MoveNext () [0x003b7] in <599fbedd978e4fce934746a63a740a87>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at Discord.Net.WebSockets.GatewaySocket+<Connect>d__12.MoveNext () [0x0013f] in <599fbedd978e4fce934746a63a740a87>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at Discord.DiscordClient+<BeginConnect>d__78.MoveNext () [0x00351] in <599fbedd978e4fce934746a63a740a87>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at Discord.DiscordClient+<BeginConnect>d__78.MoveNext () [0x005a6] in <599fbedd978e4fce934746a63a740a87>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at Discord.DiscordClient+<Connect>d__77.MoveNext () [0x0008b] in <599fbedd978e4fce934746a63a740a87>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <dca3b561b8ad4f9fb10141d81b39ff45>:0
  at PlaneSculptorsDiscordBot.Program+<Main>c__AnonStorey7+<Main>c__async6.MoveNext () [0x00085] in <a353675f20fb49b8b7b05a5467a7fc40>:0

You can find source code of the bot here: https://github.com/mzabsky/webdrafter/tree/master/bot/PlaneSculptorsDiscordBot

foxbot commented 8 years ago

what version of mono is this

LassieME commented 8 years ago

Make sure you run certmgr -ssl https://discordapp.com and certmgr -ssl https://gateway.discord.gg otherwise mono wont connect to discord over ssl.

EDIT: Just compiled your bot and ran it on my linux machine running ubuntu 16.04 without issues.

mzabsky commented 8 years ago

Mono is Stable 4.6.1.3.

I did run the two certmgr commands before posting the issue.

I suspect the error has something to do with IPv6 (other google results for that exception suggest as much), but I'm not sure what can I do about it without drilling deep into DiscordNet (or even worse the communication library it uses).

khionu commented 8 years ago

Discord.Net does nothing that specifies networking configurations. If you're machine is specifying IPv6, it's something in your machine.

EnumC commented 8 years ago

Exactly the same problem. Imported certs and using 4.6.1 mono.

Update: The problem seems to be mono itself. Downgrading from 4.6.1 to 4.4.2 fixes the issue instantly. If anyone is having this issue, looks like the temporary workaround is to just downgrade mono.

khionu commented 8 years ago

@mzabsky can you try Eric's fix, and see if that resolves it?

JaneSmith commented 8 years ago

I just started experiencing this issue too after performing an update, so that is the likely cause. I'm not entirely sure how to downgrade to 4.4.2 though.

khionu commented 8 years ago

Depends on your OS. You need to use the system's package manager to uninstall then reinstall the specific version. (I've never had to downgrade, so there might be a specific command/method for that, depending on your OS)

mzabsky commented 8 years ago

I can confirm my bot works after downgrading to Mono 4.4.2.

I assume this is not a proper solution, so I am not closing yet :)

Auralytical commented 8 years ago

We use a different networking setup in 1.0, could someone please check if this issue is present there as well?

maincoon commented 8 years ago

Expiriencing same after upgrade from 4.2 to 4.6.1. Connecting using WebSocket4Net to even ws:// not wss:// scheme and got this:

[DEBUG] <DMPCLIENT> 11-02 08:42:16: Starting ws://c1.XXXXXX.com/wsc/
[ERROR] <DMPCLIENT> 11-02 08:42:16: Can't start WSDMPClient - Exception has been thrown by the target of an invocation.,   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004d] in /builddir/build/BUILD/mono-4.6.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:313
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /builddir/build/BUILD/mono-4.6.1/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229
  at SuperSocket.ClientEngine.ConnectAsyncExtension.ConnectAsync (System.Net.EndPoint remoteEndPoint, SuperSocket.ClientEngine.ConnectedCallback callback, System.Object state) [0x00039] in <4ba236fbf29248a4985a92e6e3907e4a>:0
  at SuperSocket.ClientEngine.TcpClientSession.Connect () [0x00074] in <4ba236fbf29248a4985a92e6e3907e4a>:0
  at WebSocket4Net.WebSocket.Open () [0x0003a] in <4ba236fbf29248a4985a92e6e3907e4a>:0
  at DMPUtils.WSDMPClient.OnStart () [0x00046] in <08c32b8c89594a5db0dd068de82c3c6d>:0
[ERROR] <DMPCLIENT> 11-02 08:42:16: InnerException - An address incompatible with the requested protocol was used,   at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x0005e] in /builddir/build/BUILD/mono-4.6.1/mcs/class/System/System.Net.Sockets/Socket.cs:212
  at System.Net.Sockets.Socket.ConnectAsync (System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in /builddir/build/BUILD/mono-4.6.1/mcs/class/System/System.Net.Sockets/Socket.cs:1361
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /builddir/build/BUILD/mono-4.6.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:305
mcmonkey4eva commented 7 years ago

This is a live issue (see #442 ) and needs quick resolution.

FiniteReality commented 7 years ago

@mcmonkey4eva Use mono 4.4.2 - people are reporting that downgrading fixes the issue.

mcmonkey4eva commented 7 years ago

Still, being incompatible with latest runner code is a big problem, and should be addressed as quickly as possible.

FiniteReality commented 7 years ago

It isn't really a big problem, especially when 0.9 isn't even being actively maintained anymore. If the problem exists in 1.0, then it may be addressed.

khionu commented 7 years ago

It won't be recommended to use Mono, anyways, for 1.0. .NET Core works for most platforms, now, all but ARM, if you counter Docker Deployment, but even with ARM, that's scheduled for .NET Core this Quarter.

mcmonkey4eva commented 7 years ago

... I didn't realize there was a 1.0 available. Thanks, I'll see if I can get that one working...

mcmonkey4eva commented 7 years ago

... new question, how do I acquire Discord.NET 1.0? Nuget does not have it as the readme claims (nuget is at 0.9.6), and compiling it from .NET Core CLI just gives failure messages :( Just a lot of

MSBUILD : error MSB1009: Project file does not exist.
Switch: src\Discord.Net
Microsoft (R) Build Engine version 15.1.458.808
Copyright (C) Microsoft Corporation. All rights reserved.

under dotnet: 1.0.0-preview5-004275 which is latest currently.

FiniteReality commented 7 years ago

Check the README in the dev branch. If you're still having issues, open up a new issue as 1.0 is unrelated to this issue.

foxbot commented 7 years ago

Stale issue, closing