Harden Ghidra remote server shutdown#200
Open
amattas wants to merge 1 commit into
Open
Conversation
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.
Problem
BinSync's Ghidra integration runs a declib
DecompilerServerinside Ghidra and talks to it from a separate UI process. Two lifecycle issues make failures hard to diagnose and can crash or strand Ghidra:DecompilerClient.shutdown_server()sentshutdown_deci, which tears down the decompiler interface but does not ask the server loop itself to stop. The server already has ashutdown_serverhandler for that, but the client was not using it.Together, these make the Ghidra remote path fragile: errors can leave the server running, and backend calls can execute on unsafe threads.
Solution
GhidraDecompilerInterfaceinstances as requiringDecompilerServermain-thread dispatch.headless=Trueinstances.DecompilerClient.shutdown_server()to send the server's realshutdown_serverrequest before disconnecting.Verification
PYTEST_ADDOPTS='-p no:cacheprovider' conda run -n ghidra python -m pytest tests/test_client_server.py::TestClientServer::test_shutdown_server_requests_server_stop tests/test_ghidra_server_dispatch.py -q->2 passedPYTHONPYCACHEPREFIX=/tmp/declib-pyc conda run -n ghidra python -m compileall -q declib testsgit diff --checkDependency
The BinSync Ghidra lifecycle PR depends on this declib change for the full fix: BinSync can wait on main-thread-dispatch servers and ask the remote server to stop, but declib must expose that Ghidra requires main-thread dispatch and must route
shutdown_server()to the server stop handler.Notes
The broader declib Ghidra integration suite was not used for this PR because this local checkout is missing the external
/Users/amattas/GitHub/bs-artifacts/binaries/fauxwarefixture. The focused unit tests cover the behavior changed here without requiring that binary.