sonic-sairedis icon indicating copy to clipboard operation
sonic-sairedis copied to clipboard

[Recorder]: Acquire lock for ofstream changes

Open theasianpianist opened this issue 2 years ago • 2 comments

While the Recorder is writing to the sairedis log file, it's possible for a log rotate to occur at exactly the right time so that file stream used for writing (a std::ofstream) is re-opened in the middle of the write operation (since writing and log rotate are handled by separate threads). Since standard library objects are not thread safe, this can cause some pointers used during the write operation to be overwritten, leading to a segmentation fault when the write operation proceeds.

To prevent this from occurring, acquire a lock for the file stream for any methods that change the ofstream (including opening, closing, and writing to it with the << operator). Also use recordLine for all writes to the file stream to avoid deadlock.

Signed-off-by: Lawrence Lee [email protected]

theasianpianist avatar Nov 04 '22 01:11 theasianpianist

mutex t here could cause deadlock

kcudnik avatar Nov 09 '22 21:11 kcudnik

mutex t here could cause deadlock

which line are you referring to?

theasianpianist avatar Nov 10 '22 02:11 theasianpianist

/Azp run

theasianpianist avatar Nov 16 '22 18:11 theasianpianist

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Nov 16 '22 18:11 azure-pipelines[bot]