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

Stop sharing when Tor stops during startup #52

Merged
merged 9 commits into from
Sep 21, 2022

Conversation

grote
Copy link
Collaborator

@grote grote commented Jun 17, 2022

Each manager is now publishing its own state flow and the share manager combines all three into one sharing state flow, so it can update that state even after sharing is complete and the onionshare was published.

Related to #12

@grote grote requested a review from akwizgran June 17, 2022 19:10
@grote grote force-pushed the react-to-tor-stopping-during-startup branch from 5710dcf to 0c397aa Compare July 6, 2022 17:39
// release persistable Uri permissions again
shareState.value.files.forEach { file ->
file.releaseUriPermission()
LOG.error("Unhandled state: ↑")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire shareState method is quite a beast and does not handle all permutations of states. If there's any suggestions how to reconcile the states of the various sub-systems in a better way, please let me know!

ensureActive()
// When the current scope gets cancelled, the async routine gets cancelled as well
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the same apply to torManager.start() below? What are the implications of cancelling that call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there a JobCancellationException gets thrown which we catch and call stop() which stops Tor again.

@Suppress("BlockingMethodInNonBlockingContext")
private suspend fun startSharing() {
if (startSharingJob?.isActive == true) {
// TODO check if this always works as expected
startSharingJob?.cancelAndJoin()
}
shouldStop.value = false
// Attention: We'll launch sharing in Global scope, so it survives ViewModel death
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment?

If we're no longer using the global scope then does the job still survive the death of the view model?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh good catch. Through some corners this actually inherits the ViewModelScope, so this needs to go back to GlobalScope.

@akwizgran
Copy link
Collaborator

I rebased this branch on master and left it running over the weekend. Tor started successfully, which hasn't happened on master in many attempts. Shortly after the onion address appeared I was able to open the download page in Tor Browser. I didn't download the file.

After about 24 hours OnionShare was still running and the onion address was still shown in the UI, but the hidden service was no longer reachable in Tor Browser. The same was true this morning (about 60 hours after starting OnionShare). When I tapped the stop button in OnionShare it got stuck in the "stopping" state, with the notification still showing "Currently sharing files". It stayed in this state for several hours. Exiting the app via the back button and relaunching didn't make a difference. Eventually I had to force-stop the app.

Unfortunately since the app was running for so long, all the useful information had expired from the system log. I'll try to reproduce this without leaving the app running for so long.

@grote grote force-pushed the react-to-tor-stopping-during-startup branch from 3535334 to 8c1e488 Compare July 15, 2022 13:45
@grote grote force-pushed the react-to-tor-stopping-during-startup branch from 8c1e488 to 3573ca1 Compare August 18, 2022 14:42
@grote grote force-pushed the react-to-tor-stopping-during-startup branch from 3573ca1 to 8f0af15 Compare September 21, 2022 16:24
@grote grote merged commit e9af5ae into onionshare:main Sep 21, 2022
@grote grote deleted the react-to-tor-stopping-during-startup branch September 21, 2022 17:37
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

Successfully merging this pull request may close these issues.

2 participants