Fix race condition in MonitorConnectionClient #160
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
Undefined order of execution between
monitorConnectionClient.eventLoop()
goroutine that passes events tofanoutEventCh
and goroutine that's waiting<--context.Done()
and closesfanoutEventCh
leads to different number oftestOnHeal.Request()
calls in/pkg/networkservice/common/heal/client_test.go
TestNewClient_MissingConnectionsOnInit
test that leads to different number (2 or 3)testOnHeal.Request()
invocations. Explanation diagramSolutions i see:
time.Sleep(100 * time.Millisecond)
after sendingINITIAL_STATE_TRANSFER
event to ensure that this event will be handled earlier than context cancellation.Guarantee that chain context cancellation will be handled after connection event, if it was cancelled after connection event sending. One way to do that i see is to emulate the server falling down by closing
eventCh
, not chain context cancelling. Chain context cancelling is rather about client's intention to shut down and logically may be async, but server's falling down is not.Tried to implement the second one in this PR :)