-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(libtor): prevent concurrent instances #1445
Conversation
We should probably remove this check before merging
Tests for libtorlinux passed in https://github.com/ooni/probe-cli/actions/runs/7532480622/job/20503178535, which was building 376a8f5. So, now I can revert the little piece of GitHub Action changes that caused the build to trigger. |
I failed to run the test referenced above, in an arch-based system. Sounds like the build tool is missing to link against
|
Yes, it seems the |
@ainghazal I summarized our discussion here: ooni/probe#2651. |
Co-authored-by: Ain Ghazal <[email protected]>
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 <[email protected]>
This PR is about preventing concurrent
./internal/libtor
instances. The./internal/libtor
package links withlibtor.a
and runstor_run_main
. The expectation of such a function is that a single thread can execute within the same process. If we attempt to invoketor_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:
to compile tor and its dependencies for GNU/Linux. (You would need
build-essential
,autoconf
,automake
, andlibtool
being installed on a Debian system.)Then, run tests using:
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 wheretor
is running as a daemon.Closes ooni/probe#2623