alanmcgovern / Mono.Nat

UPNP and NAT-PMP port forwarding for .NET
https://github.com/mono/Mono.Nat
MIT License
160 stars 156 forks source link

Fixed NatUtility.StopDiscovery() hanging indefinitely in Windows Forms app #30

Closed bp2008 closed 3 years ago

bp2008 commented 3 years ago

To fix NatUtility.StopDiscovery() hanging in a Windows Forms app, I had to add several ConfigureAwait(false) calls. Along the way to fixing this, I also added code to honor CancellationTokens in a few places they were being ignored. I can't promise there are no unintended consequences to these changes, but I think it should be an overall improvement to reliability.

This pull request also includes the same fix I submitted earlier in this unrelated pull request: https://github.com/alanmcgovern/Mono.Nat/pull/29

simonchiarel commented 3 years ago

I think this may fix a similar problem when Using Pmp discovery in Unity

alanmcgovern commented 3 years ago

I'm just reviewing this now. I think i might solve it a slightly different way, but i'll base my changes on top of your patch as it's mostly the right approach!

alanmcgovern commented 3 years ago

I took some of these changes, but not all of them. Let me know if the current version in master is ok for your needs!

alanmcgovern commented 3 years ago

I did the first round of cleanups to give proper synchronous cleanup/shutdown which is also threadsafe.

https://github.com/alanmcgovern/Mono.Nat/pull/32

If you're doing some further testing, i'd appreciate if you tested using that branch as I'll merge that to master in the near future to fully address the issues you uncovered in this PR :)

bp2008 commented 3 years ago

Thanks. My need for UPnP/NAT-PMP testing has passed for now, but if I ever need to do it again, I'll try and remember to go back to your master branch.

alanmcgovern commented 3 years ago

No problem, and thanks for taking the time to push some changes upstream! :D

bp2008 commented 3 years ago

You're very welcome! Thanks for maintaining this project!