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: Use ring-buffer for WaitForFoo chans #1359

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

AndrewSisley
Copy link
Contributor

Relevant issue(s)

Resolves #1357

Description

Introduces ring-buffer mechanics for WaitForFoo chans. This means that the go routines modified should never block, and that means that the libp2p EventBus should never fill to capacity, meaning it too should never block, which means the main P2P code should never block when doing P2P stuff (e.g. when calling EventBus.Emit in server.PushLog).

Massive thanks to Fred and John for showing me a very simple way of creating a ring-buffer in Go, I thought it would be way more complicated to do this.

@AndrewSisley AndrewSisley added bug Something isn't working area/p2p Related to the p2p networking system action/no-benchmark Skips the action that runs the benchmark. labels Apr 17, 2023
@AndrewSisley AndrewSisley added this to the DefraDB v0.5.1 milestone Apr 17, 2023
@AndrewSisley AndrewSisley requested a review from a team April 17, 2023 17:46
@AndrewSisley AndrewSisley self-assigned this Apr 17, 2023
@codecov
Copy link

codecov bot commented Apr 17, 2023

Codecov Report

Merging #1359 (2572c6f) into develop (8a6ac5f) will decrease coverage by 0.11%.
The diff coverage is 62.50%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1359      +/-   ##
===========================================
- Coverage    70.65%   70.55%   -0.11%     
===========================================
  Files          184      184              
  Lines        17818    17833      +15     
===========================================
- Hits         12590    12582       -8     
- Misses        4275     4294      +19     
- Partials       953      957       +4     
Impacted Files Coverage Δ
node/node.go 62.59% <62.50%> (-1.38%) ⬇️

... and 5 files with indirect coverage changes

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

LGTM. Once again, thanks for spotting this. It's a small but important fix.

pubSubEvent: make(chan net.EvtPubSub),
pushLogEvent: make(chan net.EvtReceivedPushLog),
peerEvent: make(chan event.EvtPeerConnectednessChanged),
// WARNING: The current usage of these channels means that consumers of them
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: There is a chance that this 'feature' may enable tests to pass when they should not, if for example the WaitForFoo funcs are called later than they should.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is very true. But it would have been the case before as well but limited to the size of the event bus channel instead of the node channels above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah true! That's an interesting thought too, I wonder if that has been affecting things

@AndrewSisley AndrewSisley merged commit 3d43deb into develop Apr 17, 2023
12 checks passed
@AndrewSisley AndrewSisley deleted the sisley/fix/I1357-p2p-ring-buffer branch April 17, 2023 18:16
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
Fixes a deadlock-like situation within P2P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/p2p Related to the p2p networking system bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace WaitForFoo chans with ring buffer
2 participants