sonic-sairedis
sonic-sairedis copied to clipboard
[Recorder]: Acquire lock for ofstream changes
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]
mutex t here could cause deadlock
mutex t here could cause deadlock
which line are you referring to?
/Azp run
Azure Pipelines successfully started running 1 pipeline(s).