-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add support for respecting system proxy settings #41
Conversation
Started test build 34844 |
Build 34844 failed |
c9db111
to
e989299
Compare
Started test build 34845 |
Build 34845 successful
|
+ | ||
+namespace { | ||
+ | ||
+class GLibThread { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: do we actually need a separate thread here? GLib declares global structures to be thread-safe, so I believe g_proxy_resolver_lookup_async
could be called from the same thread, locking the cache if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I wasn't sure either and on a quick look at the code (portal impls) I couldn't confirm so I went with the safest option. Maybe @pwithnall would be able to confirm/clarify here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@refi64 is right: you should be able to expect that the proxy resolver returned by g_proxy_resolver_get_default()
is thread-safe.
The gsimpleproxyresolver.c
implementation is thread-safe as long as there are no calls to g_simple_proxy_resolver_set_*()
after any threads have been spawned.
The gproxyresolverportal.c
implementation is entirely thread-safe, because it just passes calls through to a GDBusProxy
around the portal, which is thread-safe.
The gproxyresolvergnome.c
implementation (in glib-networking) looks like it’s thread-safe (it has a mutex), but I haven’t checked it thoroughly.
The glibproxyresolver.c
(libproxy) implementation (in glib-networking) also looks like it has thought about threading, because it already does its libproxy calls in a worker thread.
tl;dr: You should be able to drop your worker thread here. If any threading bugs do appear, they are likely bugs in GLib; but I wouldn’t expect any to appear if you’re using any implementation except gsimpleproxyresolver.c
. It would be unlikely you’d end up using that implementation, as it’s a fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pwithnall, @refi64. I've updated the impl to drop the glib worker thread. Some possible improvements using current GProxyResolver/Portal interface APIs (for the future - I don't plan to work on them for the time being):
- avoid calls to
g_proxy_resolver_lookup()
if there is an existing inflight request for the same url- although
net::ProxyResolver::GetProxyForURL()
is always invoked from the same thread for the samenet::ProxyResolver
instance, different instances may be invoked from different threads but still use the sameGProxyResolver
instance...
- although
- using a single/global cache for all proxy resolver instances
- as above, given we use the same
GProxyResolver
instance behind the sceces, we could consider a global cache
- as above, given we use the same
- make cache smarter
- allow async
net::ProxyResolver::GetProxyForURL()
calls (although currently the only consumer isnet::MultiThreadProxyResolver
which always expects a sync call)
e989299
to
409e05d
Compare
Started test build 35109 |
Build 35109 successful
|
Ok, this is an attempt to implement support for respecting system proxy settings on the flatpak version.
Some general notes on implementation:
--winhttp-proxy-resolver
is passed as param, which uses thenet::ProxyResolver
interface to determine the proxy given an url:net::ProxyResolver::GetProxyForURL()
(instead of relying on the internal chromium mechanism based on the proxy settings, set to "mode=auto" in this case), which in turn invokesg_proxy_resolver_lookup
which uses the portal API via D-Busnet::ProxyResolver::GetProxyForURL()
, I've implemented a (very) simple cache that gets invalidated every 1min (same default timeout used on chromium dns refresh)On the bright side, it seems to work fine from my tests (could use some more tests though) and changes to the system settings (tested on GNOME/Endless) are reflected correctly (considering the cache invalidation timeout of 1min).
I am not really happy with the amount of D-Bus calls trigerred here tbh (esp. when proxy is disabled), but I can't think of another way to implement this with the current portal APIs - we could tweak the cache invalidation timeout but apart from that I don't think we could do much to improve.
See flatpak/xdg-desktop-portal#554 for the portal API issues/limitations mentioned above.
Thoughts?
Closes #36