Fix segfault caused by cross-thread QProcess read in vpnLogger#207
Open
devnix wants to merge 1 commit into
Open
Fix segfault caused by cross-thread QProcess read in vpnLogger#207devnix wants to merge 1 commit into
devnix wants to merge 1 commit into
Conversation
The vpnLogger runs in a dedicated thread but was calling QProcess::read() on a QProcess owned by the main thread. This caused QRingBuffer corruption and segfaults, especially under heavy I/O. Read QProcess data in its owning thread via a DirectConnection lambda, then queue the already-read data to the logger thread for processing. Also fix null pointer dereferences in vpnProcess timer callbacks and stop timers before thread cleanup in closeProcess().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: While I can read C/C++ to a certain extent, I've fully worked on fixing this issue with AI. I don't want, by any means, to pollute repositories with slop.
If I should make changes, I would love to have the opportunity to learn more from a review. Thank you for your patience! 🙏🏼
Summary
vpnLoggerruns in a dedicatedQThreadbut was callingQProcess::read()on aQProcessowned by the main thread via aQSignalMapperqueued connection. This causedQRingBuffercorruption and frequent segfaults, especially under heavy VPN I/O (large downloads).QProcessdata in its owning thread using aDirectConnectionlambda onreadyReadStandardOutput, then queue the already-readQByteArrayto the logger thread viaQMetaObject::invokeMethodfor processing.vpnProcess:thread_workerandptr_tunnelinonObserverUpdate(),updateStats(), andonStatsUpdate()timer callbacks.closeProcess()to prevent use-after-free.nullptrin the constructor.logMapperStdout, deadlogVPNOutputslot, unusedloglockermap, and add proper cleanup of per-VPN maps inprocFinished()to prevent resource leaks on reconnect.Crash backtrace (before fix)
Test plan