Skip to content

Fix potential SIGSEGV in Replicator - #205

Open
gamerioo wants to merge 3 commits into
ankur-anand:mainfrom
gamerioo:fix-sigsegv
Open

Fix potential SIGSEGV in Replicator#205
gamerioo wants to merge 3 commits into
ankur-anand:mainfrom
gamerioo:fix-sigsegv

Conversation

@gamerioo

Copy link
Copy Markdown

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.

@ankur-anand

Copy link
Copy Markdown
Owner

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 localrun

https://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

@ankur-anand

Copy link
Copy Markdown
Owner

@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.

@gamerioo

gamerioo commented Feb 1, 2026

Copy link
Copy Markdown
Author

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 localrun

https://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

Sure sir would love to I'll figure this out today itself just gimme some time

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.

Potential SIGSEGV in Replicator

2 participants