Fix potential SIGSEGV in Replicator - #205
Conversation
|
Thanks, Looks Good to me. Can you do me a favour and run a benchmark and post a number on how much this impacts the realyer and its throughput? the benchsetup from localrunhttps://github.com/ankur-anand/unisondb?tab=readme-ov-file#performance-testing-local-replication You can run this on your local machine on two different branches and just compare the numbers for various relayer counts. The Redis-compatible server implementation can be found in internal/benchtests/cmd/redis-server/. https://github.com/ankur-anand/unisondb/tree/main/internal/benchtests/cmd/redis-server |
|
@gamerioo Somehow GitHub codes scanning result seems to be stuck. Just do a git empty commit on this branch again to trigger the code scan result back. |
Sure sir would love to I'll figure this out today itself just gimme some time |
Fixes #186
SUMMARY
This PR fixes a potential segmentation fault (SIGSEGV) in the Replicator caused by a race condition between the file reader closing and the async streamer accessing memory-mapped data.
SOLUTION
I have modified pkg/replicator/replicator.go inside the replicateFromReader function.
Instead of passing the raw memory-mapped pointer (value) directly to the channel, I now perform a deep copy of the data into a new byte slice.
This decouples the data sent to the streamer from the file system lifecycle. Even if reader.Close() is called and the file is unmapped, the Streamer now holds its own private copy of the data in the heap, preventing the crash.