RiptideNetworking / Riptide

Lightweight C# networking solution for multiplayer games.
https://riptide.tomweiland.net
MIT License
1.13k stars 144 forks source link

Likely Unity's fault: "Only one usage of each socket address (protocol/network address/port) is normally permitted" #82

Open megalithos opened 1 year ago

megalithos commented 1 year ago

Yes, I submitted the same issue before.

I don't know how to reproduce, I get the issue after some time when I have stopped and started play mode in unity editor multiple times. It gets fixed when I restart the unity editor.

tom-weiland commented 1 year ago

53 was the previous issue (just for reference).

I had someone else complain about this same error on Discord just the other day. It's caused by the socket not being shut down correctly (even though—as far as I know—it should be when calling Server.Stop in OnApplicationQuit), and restarting the editor fixes it because that cleans it all up.

I myself haven't run into this error in several months, which makes debugging it virtually impossible. Any additional information about in which scenarios/what you were doing when the error occurs would be extremely helpful, particularly if you notice any patterns.

Even just putting a Debug.Log line after the Server.Stop call to confirm that it's running when you get the error would be a good start.

megalithos commented 1 year ago

I have a bit more info: my friend is making rpg with unity and he gets the same error with Mirror networking solution. He also fixes it just by restarting Unity.

tom-weiland commented 1 year ago

That's helpful to know, but still isn't definitive—either Mirror has the same problem or something about the Unity editor prevents it from shutting sockets down properly...

The last time I personally ran into this (months and months ago), I think it may have been after making code changes while the editor was in play mode. Perhaps when Unity rebuilds/reloads the code it either messes with running sockets or prevents the shutdown code from running? That was a long time ago and may have just been a one-off though, so if anyone else can provide more context regarding the conditions/timing/circumstances of this error, that'd be a big help.

megalithos commented 1 year ago

Yeah that sounds like a valid theory. My guess is that the bug happens with some chance (like 0,1% chance) (lol) when the code is edited & unity is stopped while it is running like you said. So it would be internal bug in unity itself.

tom-weiland commented 1 year ago

when the code is edited & unity is stopped while it is running

Yeah, I've noticed it happening under those circumstances, but I can't confirm that that's the only time it happens :/