Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support for mapping multiple listener address #1183

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

munna0908
Copy link
Contributor

This PR will fix #1158

@munna0908 munna0908 added the bug Something isn't working label Apr 1, 2025
@munna0908 munna0908 requested review from dryajov and gmega April 1, 2025 16:54
@munna0908 munna0908 self-assigned this Apr 1, 2025
@munna0908 munna0908 marked this pull request as ready for review April 3, 2025 09:00
Copy link
Member

@gmega gmega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks OK, but I'm not convinced about the safety of some of those things. Need to have them clarified first.

@@ -287,7 +287,7 @@ proc new*(
interval = config.blockMaintenanceInterval,
numberOfBlocksPerInterval = config.blockMaintenanceNumberOfBlocks,
)

natManager = NatManager.new(config.nat)
Copy link
Member

@gmega gmega Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Hm... not sure I'm very comfortable scoping the object that gets its reference passed onto another thread here. What you had before were a bunch of module-private globals so I think that was OK, but here you may find yourself with unwanted accesses to fields in this object if someone later doesn't realize this is not safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we were using primitive globals, but now we need to store a sequence of entries—which isn't GC-safe—so we can't use globals anymore. I believe the current implementation is the simplest and cleanest approach. Do you have any alternative suggestions?

Note: Only a single thread accesses the NatManager attributes, so there's no concern around concurrent access.

Copy link
Member

@gmega gmega Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you're also initializing a ref object that contains a sequence and then passing it to another thread to access. What am I missing? How's that more GC-safe than having it as a module-private global? You could even have NatManager itself as a module-level private.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw I realize we're not currently accessing NatManager from multiple threads, what I meant to say is that we are leaving a reference to it here which someone in the future might misuse.

portMappings: seq[PortMapping]
thread: Thread[ptr NatManager]
config: NatConfig
upnp: Miniupnp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Those were threadvars before and initialized per-thread. Why are we not doing that anymore, and is it safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmega I moved pnp and upnp into the NatManager object for sanity and consistency. They are initialized once by the main Chronos thread and then used by another thread. Since we retain a reference to NatManager throughout the lifecycle, I don’t foresee any issues. That said, we can still convert them to threadvars if you think it's more appropriate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't know, I don't know why they were done as threadvars in the first place, but it would seem to indicate that you can't initialize them in one thread then use them in another. Previously we had them as module-level globals, which are also stable references? Am I missing anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Client hanging on exit (NAT related?)
2 participants