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

connmgr: fix concurrent map misuse. #1857

Closed
wants to merge 1 commit into from

Conversation

cachalots
Copy link

@cachalots cachalots commented Nov 8, 2022

fix #1847 ipfs/kubo#9374

// but since inf.conns is a map, it will still point to the original object

Loop conns is not locked, causing concurrent map misuse.

This repair method needs to modify more code, so I didn't choose to use this method.

type peerInfos  []peerInfo

// replace to
type peerInfos struct {
	peerInfo []peerInfo
	segments segments
}

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

That doesn't seem like a very intuitive API. peerInfo is just a []peerInfo, and has no (obvious) connection to segments (which just holds a map of peerInfos).

@cachalots
Copy link
Author

That doesn't seem like a very intuitive API. peerInfo is just a []peerInfo, and has no (obvious) connection to segments (which just holds a map of peerInfos).

I just put forward this idea. The code just add parameter segments to the method SortByValueAndStreams to get lock.

@p-shahi
Copy link
Member

p-shahi commented Nov 8, 2022

Thanks for the initiative and providing logs @cachalots! I will close this in favor of #1860

@p-shahi p-shahi closed this Nov 8, 2022
@MarcoPolo
Copy link
Collaborator

Thanks for looking into this @cachalots. I put a fix here: #1860. It's worth pointing out that this PR has two possible deadlocks.

  1. both left and right are in the same segment.
  2. goroutine 1 locks A then B, goroutine 2 locks B then A.

s hard Concurrency i.

I'm closing this pr and proceeding with #1860 (feel free to give that a review!), but I appreciate the effort. In the mean time, if you're looking for other places to contribute you could take a look at: #1707 especially since you've already familiarized yourself with the connmgr.

@cachalots cachalots deleted the fix-concurrent-map-misuse branch November 9, 2022 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

connmgr: Concurrent Map Misuse
4 participants