Skip to content

8353662: Add test for non-local file URL fallback to FTP #24418

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

Closed
wants to merge 3 commits into from

Conversation

eirbjo
Copy link
Contributor

@eirbjo eirbjo commented Apr 3, 2025

Please review this test-only PR which introduces testing of the unspecified but long-standing fallback to FTP for non-local files in the 'file' URL scheme.

This in preparation for the upcoming proposal to disable the feature by default in JDK-8353440.

Since we cannot reliably bind an FTP server to port 21, the test instead uses an HTTP proxy, binding to an ephemeral port. This menas we don't test non-proxy code paths. We still test that the FTP fallback is used, which is the key point here. (We aim to test file URL connections, not FTP URL connection internals)

An alternative here could be to just verify that the returned URLConnection is an instance of FtpURLConnection. However, I opted for an end-to-end test here, since the amount of extra code seems reasonable.

By temporarly moving this test to tier1, I was able to confirm this test runs green also on Windows GHA.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8353662: Add test for non-local file URL fallback to FTP (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24418/head:pull/24418
$ git checkout pull/24418

Update a local copy of the PR:
$ git checkout pull/24418
$ git pull https://git.openjdk.org/jdk.git pull/24418/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24418

View PR using the GUI difftool:
$ git pr show -t 24418

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24418.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 3, 2025

👋 Welcome back eirbjo! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 3, 2025

@eirbjo This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8353662: Add test for non-local file URL fallback to FTP

Reviewed-by: dfuchs

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 271 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Apr 3, 2025

@eirbjo The following labels will be automatically applied to this pull request:

  • core-libs
  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org net net-dev@openjdk.org labels Apr 3, 2025
@eirbjo eirbjo changed the title Add a test verifying non-local file: URL fallback to FTP 8353662: Add test for non-local file URL fallback to FTP Apr 3, 2025
@eirbjo eirbjo force-pushed the non-local-file-ftp-test branch from 461f1c3 to f235d79 Compare April 3, 2025 17:56
@eirbjo eirbjo marked this pull request as ready for review April 4, 2025 04:46
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 4, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 4, 2025

Webrevs

@AlanBateman
Copy link
Contributor

/label remove core-libs

@openjdk openjdk bot removed the core-libs core-libs-dev@openjdk.org label Apr 4, 2025
@openjdk
Copy link

openjdk bot commented Apr 4, 2025

@AlanBateman
The core-libs label was successfully removed.

@Test
public void verifyNonLocalFtpFallback() throws Exception {
URL localURL = file.toUri().toURL();
URL nonLocalURL = new URL("file", "127.0.0.1", localURL.getFile());
Copy link
Member

@dfuch dfuch Apr 4, 2025

Choose a reason for hiding this comment

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

The URL should not assume that the loopback is an IPv4 address. Or is this handled by the proxy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The URL should not assume that the loopback is an IPv4 address. Or is this handled by the proxy?

Right. The following returns "127.0.0.1" for me, would that be the correct API to use?

InetAddress.getLoopbackAddress().getHostAddress()

Copy link
Member

Choose a reason for hiding this comment

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

Ok - I see that 127.0.0.1 should not be directly used. Would it work if we replaced that with a fake host name then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok - I see that 127.0.0.1 should not be directly used. Would it work if we replaced that with a fake host name then?

Yeah, you're right, the FTP request never materializes (our proxy just swallows it). So we only use it to assert against what was requested from the proxy, we can use a fake host name.

Any preference/precedence for fake host names?

Copy link
Member

Choose a reason for hiding this comment

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

Generally looks good. "127.0.0.1" rings alarm bells because we're trying to make our tests independent of the IP versions supported by the machine they run on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally looks good.

Does this mean you think the PR is good for approval now that the IP version aspect has been taken care of?

Or would you like more time/people to review this test-only enhancement?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry - thanks for pinging me.
I tested the change in our CI and the new test seem stable. Approved.

@eirbjo
Copy link
Contributor Author

eirbjo commented Apr 4, 2025

@dfuch Tagnential observation: proxyServer.stop(2) will always wait 2 seconds here. I was assuming it would only do that if there was an ongoing exchange.

Looking at the ServerImpl class, it looks like finished is never set to true. Specifically, ServerImpl.Dispatcher::handleEvent does not set it to true since that happens before terminating is set to true.

How is HttpServer::stop expected to work? Is something wrong with my expectations that this should return quickly with no inflight exchanges?

@dfuch
Copy link
Member

dfuch commented Apr 4, 2025

@dfuch Tagnential observation: proxyServer.stop(2) will always wait 2 seconds here. I was assuming it would only do that if there was an ongoing exchange.

Looking at the ServerImpl class, it looks like finished is never set to true. Specifically, ServerImpl.Dispatcher::handleEvent does not set it to true since that happens before terminating is set to true.

How is HttpServer::stop expected to work? Is something wrong with my expectations that this should return quickly with no inflight exchanges?

Interesting. That looks like a bug to me. stop() should probably look at exchangeCount too - but that will require some thinking to get the asynchronous stops to work correctly. Should be worth logging a bug :-)

@eirbjo
Copy link
Contributor Author

eirbjo commented Apr 4, 2025

Interesting. That looks like a bug to me. stop() should probably look at exchangeCount too - but that will require some thinking to get the asynchronous stops to work correctly. Should be worth logging a bug :-)

Let's see if this captures the essence:

https://bugs.openjdk.org/browse/JDK-8353720

EDIT: There was already a bug filed for this: https://bugs.openjdk.org/browse/JDK-8304065

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 11, 2025
@eirbjo
Copy link
Contributor Author

eirbjo commented Apr 11, 2025

Thanks you Daniel for running this through CI and for the review.

/integrate

@openjdk
Copy link

openjdk bot commented Apr 11, 2025

Going to push as commit cae7a20.
Since your change was applied there have been 271 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 11, 2025
@openjdk openjdk bot closed this Apr 11, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 11, 2025
@openjdk
Copy link

openjdk bot commented Apr 11, 2025

@eirbjo Pushed as commit cae7a20.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

3 participants