-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(libtor): prevent concurrent instances (#1445)
This PR is about preventing concurrent `./internal/libtor` instances. The `./internal/libtor` package links with `libtor.a` and runs `tor_run_main`. The expectation of such a function is that a single thread can execute within the same process. If we attempt to invoke `tor_run_main` while another instance is running, this is most likely going to cause memory corruption because the two instances try to operate on the same static data structures. To address this issue, we use atomic compare and swap and atomic set to make sure there is just a single thread inside the "critical section" consisting of calling `tor_run_main`. All the other threads would fail with an error. To test this branch on Linux, you need to run: ```sh go run ./internal/cmd/buildtool linux cdeps zlib openssl libevent tor ``` to compile tor and its dependencies for GNU/Linux. (You would need `build-essential`, `autoconf`, `automake`, and `libtool` being installed on a Debian system.) Then, run tests using: ```sh go test -tags ooni_libtor -v ./internal/libtor/... ``` These tests should pass on a GNU/Linux system. In addition to making sure we cannot have concurrent instances, this PR also modifies some tests that were not using `SocksPort auto`. As a result, those tests would fail in a system where `tor` is running as a daemon. Closes ooni/probe#2623 --------- Co-authored-by: Ain Ghazal <99027643+ainghazal@users.noreply.github.com>
- Loading branch information
1 parent
64f61ec
commit a62f36c
Showing
2 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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