567f5739bd25773daeb2615718125731ea6c5b3a — Jack Mordaunt 3 months ago 3166b2e
list: [fix] copy state update slice to avoid data race

I observed a data race between layout and the process goroutine that
appears to be a result of sharing the element slice.

While querying for which serials are in the viewport during layout, the
async process was updating those same elements during a modify request.

After reviewing the code I concluded that the slice was being shared and
should rather be copied before reaching layout - that is, before being
sent over the updates channel.

After applying this change, I could not reproduce the race condition.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
1 files changed, 3 insertions(+), 2 deletions(-)

M list/synthesizer.go
M list/synthesizer.go => list/synthesizer.go +3 -2
@@ 62,8 62,9 @@ func (s Synthesis) ViewportToSerials(viewport layout.Position) (Serial, Serial) 
// of each resulting element to the input element that generated it.
func Synthesize(elements []Element, synth Synthesizer) Synthesis {
	var s Synthesis
	s.Source = elements
	for i, elem := range elements {
	s.Source = make([]Element, len(elements))
	copy(s.Source, elements)
	for i, elem := range s.Source {
		var (
			previous Element
			next     Element