Repository navigation
Run the listener's teardown on the GUI thread (fixes #82) - #84
Open
omnimaxxing wants to merge 1 commit into
Open
omnimaxxing wants to merge 1 commit into
omnimaxxing wants to merge 1 commit into
Conversation
When a backend disconnects, the listener thread called terminate(), which erases from the unlocked `sockets` map and then runs closeUIInstance(): coordinator->unload() changes QML properties and unregisters resources. Both race the GUI thread when the frontend closes the app at the same time, which can crash xochitl (seen as "double free or corruption"). The listener now queues that teardown onto the GUI thread. It skips it when the GUI already terminated the app, and closes the pipe's read end there, after any terminate() that might still write to it.
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.
Fixes #82.
Problem
When an app's backend disconnects, its listener thread calls
terminate(). That erases from the unlockedsocketsmap and then runscloseUIInstance()→coordinator->unload(), which emits the coordinator's QML signals and unregisters the app's resources. All of this runs off the GUI thread. If the frontend closes the app at the same time (Close tapped,unloading()→terminate()), both threads tear the same app down: the iterator race @gfr-g describes in #82, plus QML changes from a non-GUI thread. On a Paper Pure this crashes xochitl, asdouble free or corruptionor SIGSEGV.Change
The listener no longer tears down on its own thread. It queues the teardown onto the GUI thread with
QMetaObject::invokeMethod(qApp, …, Qt::QueuedConnection):terminate()on the GUI thread as before, so the UI still closes when a backend dies.socketsentry is gone and the queued call does nothing. Before, the listener rancloseUIInstance(id, true)a second time.terminate()on the GUI thread never writes to a pipe whose reader is already closed.So
socketsis only erased, and apps only unloaded, on the GUI thread, without new locks or refcounts.Not in this PR
_registerSocket()still inserts intosocketsfrom the listener thread, andbroadcastMessageToControllers()readsendpointsthere. Both are less likely to collide (they happen at connect time and per message), but they belong in the same follow-up if you want the maps fully single-threaded.Testing
On a reMarkable Paper Pure, firmware 3.29.1.0, with
appload.sobuilt by this repo's release workflow (aarch64 toolchain image):df974a6+ this changeThe repro is @gfr-g's recipe from #82: a minimal app whose frontend, on tap, sends its backend a message and calls
close(). The backend exits the moment it reads any message, without waiting for AppLoad to close the socket.management.cpp,AppLoadCoordinator.cppandlibrary.cppare the same in 0.6.0 anddf974a6, so the two builds take the same shutdown path.Repro app (manifest id
close-race,loadsBackend: true)ui/main.qml:backend/main.go(built withCGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build):With this change I also checked:
Side note:
xovi/make.shcurrently exits 141 in the release workflow (rcc | sed -n '/#ifdef/q;p'gets SIGPIPE underpipefail), for both toolchain images. For these test builds I wrote rcc's output to a file first; that change isn't part of this PR.