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

fail proxy pac on windows if no URL #5935

Merged
merged 1 commit into from
May 12, 2023
Merged

Conversation

ebarboni
Copy link
Contributor

This is a "fix" to get rid of an annoying exception thrown on every launchd as info during windows autoproxy.
I'm not sure this is right approach but "to me" as no URL are set I don't get why it should use http://wdap/wdap.dat.
So exiting early.

That the exception scaring user :p :
INFO [org.netbeans.core.network.proxy.ProxyAutoConfig]: InputStream for http://wpad/wpad.dat throws
java.net.UnknownHostException: wpad
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.base/java.net.Socket.connect(Socket.java:583)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:531)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:636)
at java.base/sun.net.www.http.HttpClient.(HttpClient.java:279)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:384)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:406)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1309)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1287)
at java.base/sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1118)
at java.base/sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1116)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:962)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1115)
at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1057)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1665)
at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1581)
at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1579)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:962)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1578)
at org.netbeans.core.network.proxy.ProxyAutoConfig.downloadPAC(ProxyAutoConfig.java:155)
[catch] at org.netbeans.core.network.proxy.ProxyAutoConfig.initEngine(ProxyAutoConfig.java:94)
at org.netbeans.core.network.proxy.ProxyAutoConfig$1.run(ProxyAutoConfig.java:82)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)

@matthiasblaesing
Copy link
Contributor

To my understanding the download URL http://wpad/wpad.dat is correct. The system will resolve the host wpad in the local DNS prefix. And try to download the wpad file from there. This can be read into

https://datatracker.ietf.org/doc/html/draft-ietf-wrec-wpad-01#section-4.4.3

To get that URL on Windows, the following sequence has to run:

The system is queried for proxy configuration:

WindowsNetworkProxyLibrary.ProxyConfig.ByReference prxCnf = new WindowsNetworkProxyLibrary.ProxyConfig.ByReference();
boolean result = WindowsNetworkProxyLibrary.LIBRARY.WinHttpGetIEProxyConfigForCurrentUser(prxCnf);

Only if that is present:

https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpgetieproxyconfigforcurrentuser

And only if there is no PAC url configured, but autodetection is enabled:

https://learn.microsoft.com/en-us/windows/win32/api/winhttp/ns-winhttp-winhttp_current_user_ie_proxy_config

if (pacFilePointer != null || prxCnf.autoDetect) {
String pacFileUrl = pacFilePointer != null ? pacFilePointer.getWideString(0) : "http://wpad/wpad.dat"; // NOI18N

that URL is returned.

Sounds reasonable to me.

It was added recently: #5210 and maybe the java.net.UnknownHostException should be caught and a sensible message issued. This PR would just reintroduce the issue, that was fixed by #5210.

@sdedic could you have a look at this?

@ebarboni
Copy link
Contributor Author

@matthiasblaesing thanks for precision. I have no idea why wpad not working on my computer and others. By the way more simple PR with only a triage of exception
(we have domain controled computer and it fail)

@sdedic
Copy link
Member

sdedic commented May 12, 2023

@ebarboni thanks for the update. The UnknownHostException catch handler is indeed missing - but I'd say it should not log at all, or just note something like PAC script {0} unavailable, proxy disabled. It usually happens on systems with autoproxy enabled or even the URL configured that are outside of the proxied network. Then the DNS resolver does not know the hostname wpad and the automatic proxy configuration ends.

http://wpad/wpad.dat (hostname w/o the domain suffix) is used as a default in a hope that the OS resolver will add the domain name(s) from the domain search list and find a suitable one.

@ebarboni ebarboni changed the base branch from master to delivery May 12, 2023 10:50
@ebarboni ebarboni changed the base branch from delivery to master May 12, 2023 10:50
@ebarboni
Copy link
Contributor Author

@sdedic I do the proposed Info log message

@ebarboni ebarboni marked this pull request as ready for review May 12, 2023 11:40
@sdedic sdedic added this to the NB19 milestone May 12, 2023
@ebarboni ebarboni merged commit 775d169 into apache:master May 12, 2023
34 checks passed
@mbien mbien added the Platform [ci] enable platform tests (platform/*) label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:windows Platform [ci] enable platform tests (platform/*)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants