Skip to content

fix: improve wake & sleep handling #74

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

Merged
merged 3 commits into from
Feb 24, 2025
Merged

Conversation

ethanndickson
Copy link
Member

No description provided.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@@ -142,6 +142,11 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable {
}

override func wake() {
guard !reasserting else { return }
Copy link
Member Author

Choose a reason for hiding this comment

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

macOS does indeed wake a bunch during sleep to check the network. For us dogfooding, this means it might attempt to download a new dylib while the device sleeps, which the user won't be able to approve. In that case it'll get stuck in reasserting, in this case (and in any case, really) we don't want to try and start it up a second time.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Would you also mind adding that as a code comment?

Comment on lines 125 to 129
globalXPCListenerDelegate.vpnXPCInterface.manager = nil
self.manager = nil
completionHandler()
}
self.manager = nil
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We want self.manager being nil to be our code's perspective as to whether a stop operation has actually finished. Before, it was nil a little too early, though I don't think it was causing any issues.

Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding that as a code comment?

Comment on lines +146 to +149
guard manager == nil else {
logger.error("wake called with non-nil Manager")
return
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was previously in the start function called right after, but we should avoid resetting the network settings needlessly if we can.

@ethanndickson ethanndickson marked this pull request as ready for review February 21, 2025 01:30
Copy link
Member

@ThomasK33 ThomasK33 left a comment

Choose a reason for hiding this comment

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

LGTM, small remarks about getting some comments in.

@ethanndickson ethanndickson merged commit f970cfc into main Feb 24, 2025
4 checks passed
@ThomasK33 ThomasK33 deleted the ethan/improve-sleep branch February 25, 2025 13:44
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