Skip to content
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

Restart Tor #20

Closed
aayushsinha44 opened this issue Feb 29, 2020 · 4 comments
Closed

Restart Tor #20

aayushsinha44 opened this issue Feb 29, 2020 · 4 comments

Comments

@aayushsinha44
Copy link

aayushsinha44 commented Feb 29, 2020

I am using tor and generating onion url and associating it with a http server. Whenever my internet connection is lost the tor circuits break. I want to restart everything at this point. For doing so, i stop my http server and close my onion and tor by tor.Close() and onion.Close(). After that i try to repeat all the process from start to start tor, onion and http service. At this moment i am unable to connect to tor. Everyting context time out occurs.
If i close the program and re-run it seems to work fine. But when i try to restart within the running program it doesnot works.

Is there some issue of tor.Close() or onion.Close()? I am unable to figure this out.

How to restart existing running tor service without stop existing running program?

@karalabe
Copy link
Member

I honestly haven't the slightest clue what might be wrong, but this is a use case I want to actively use myself too in the following days, so I'll get back to you if I figure anything out.

@karalabe
Copy link
Member

Just hit this myself too. Funky, will try to figure it out. Seems that the tor bootstrap never finishes when restarting. At least it never gives back control to the caller, even though it says "100%" booted. I've tried nuking the datadir and restarting like that and it also doesn't seem to work, so it might be something off either in the lib or in the control lib.

@karalabe
Copy link
Member

I think the (or an) issue is in the controller lib: https://github.com/cretz/bine/blob/62912bff1c531f4cb731cc86d38e78bc94aea2fd/tor/tor.go#L370

Onion creation uses tor.EnableNetwork(ctx, true), blocking until the circuit bootstraps itself. However, if the network was enabled already, the above line bail out of the method, even if waiting was requested and the circuit is not yet done. Not sure if this is the cause for the hang, but it's a weird race. Will try to fix and see.

@karalabe
Copy link
Member

I knew until now that the Tor library is not capable of running two instances in the same process. Unfortunately it also seems that it's not capable of restarting itself without restarting the entire process. My hunch is that some global variable is ruined on shutdown.

Either way, Tor does support enabling and siabling networking, so you can get away with not killing the in-process Tor, just shutting the network off and back on and it should work:

You can enable networking on request via.

tor.EnableNetwork(context.Background(), false)

Turning off the networking is not exposed in the bine library, but you can do it via:

tor.Control.SetConf(control.KeyVals("DisableNetwork", "1")...)

The lack of the latter is tracked in cretz/bine#41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants