Skip to content

Commit 758546a

Browse files
vaadin-botArtur-
andauthored
fix: Retry Node download if it fails (#16338) (#16347)
* fix: Retry Node download if it fails Fixes #16035 * Only download once when successful --------- Co-authored-by: czp13 <61667986+czp13@users.noreply.github.com> Co-authored-by: Artur <artur@vaadin.com>
1 parent 1f5db24 commit 758546a

2 files changed

Lines changed: 20 additions & 58 deletions

File tree

‎flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/MiscSingleModuleTest.kt‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -421,58 +421,6 @@ class MiscSingleModuleTest : AbstractGradleTest() {
421421
expectArchiveContainsVaadinBundle(war, false, compressedExtension)
422422
}
423423

424-
/**
425-
* https://github.com/vaadin/vaadin-gradle-plugin/issues/76
426-
*/
427-
@Test
428-
fun testNodeDownload() {
429-
430-
testProject.buildFile.writeText(
431-
"""
432-
plugins {
433-
id 'com.vaadin'
434-
}
435-
repositories {
436-
mavenLocal()
437-
mavenCentral()
438-
maven { url = 'https://maven.vaadin.com/vaadin-prereleases' }
439-
}
440-
dependencies {
441-
implementation("com.vaadin:flow:$flowVersion")
442-
}
443-
vaadin {
444-
requireHomeNodeExec = true
445-
nodeVersion = "v12.10.0"
446-
nodeDownloadRoot = "http://localhost:8080/non-existent"
447-
}
448-
"""
449-
)
450-
451-
452-
val result: BuildResult
453-
454-
// Vaadin downloads the node to ${user.home}/.vaadin.
455-
// Set user.home to be the testProject root directory
456-
val originalUserHome = System.getProperty("user.home")
457-
System.setProperty("user.home", testProject.dir.absolutePath)
458-
459-
try {
460-
result = testProject.buildAndFail("vaadinPrepareFrontend",
461-
"-Duser.home=${testProject.dir.absolutePath}")
462-
} finally {
463-
// Return original user home value
464-
System.setProperty("user.home", originalUserHome)
465-
}
466-
// the task should fail to download the node.js
467-
result.expectTaskOutcome("vaadinPrepareFrontend", TaskOutcome.FAILED)
468-
expect(true, result.output) {
469-
result.output.contains("Could not download http://localhost:8080/v12.10.0/")
470-
}
471-
expect(true, result.output) {
472-
result.output.contains("Could not download Node.js")
473-
}
474-
}
475-
476424
/**
477425
* Tests https://github.com/vaadin/vaadin-gradle-plugin/issues/99
478426
*/

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/installer/NodeInstaller.java‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class NodeInstaller {
5656

5757
public static final String PROVIDED_VERSION = "provided";
5858

59+
private static final int MAX_DOWNLOAD_ATTEMPS = 3;
60+
5961
private final Object lock = new Object();
6062

6163
private String npmVersion = PROVIDED_VERSION;
@@ -250,12 +252,10 @@ private void installNode(InstallData data) throws InstallationException {
250252

251253
extractFile(data.getArchive(), data.getTmpDirectory());
252254
} catch (DownloadException e) {
253-
getLogger().error(
255+
throw new InstallationException(
254256
"Node.js download failed. This may be due to loss of internet connection.\n"
255257
+ "If you are behind a proxy server you should configure your proxy settings.\n"
256-
+ "Verify connection and proxy settings or follow the https://nodejs.org/en/download/ guide to install Node.js globally.");
257-
throw new InstallationException(
258-
"Could not download Node.js. Check your connection and proxy settings.",
258+
+ "Verify connection and proxy settings or follow the https://nodejs.org/en/download/ guide to install Node.js globally.",
259259
e);
260260
} catch (ArchiveExtractionException e) {
261261
throw new InstallationException(
@@ -508,8 +508,22 @@ private void downloadFileIfMissing(URI downloadUrl, File destination,
508508
String userName, String password) throws DownloadException {
509509
if (!destination.exists()) {
510510
getLogger().info("Downloading {} to {}", downloadUrl, destination);
511-
fileDownloader.download(downloadUrl, destination, userName,
512-
password);
511+
for (int i = 0; i < MAX_DOWNLOAD_ATTEMPS; i++) {
512+
try {
513+
fileDownloader.download(downloadUrl, destination, userName,
514+
password);
515+
return;
516+
} catch (DownloadException e) {
517+
if (i == MAX_DOWNLOAD_ATTEMPS - 1) {
518+
throw e;
519+
}
520+
521+
getLogger().debug("Error during downloading " + downloadUrl,
522+
e);
523+
getLogger().warn("Download failed, retrying...");
524+
}
525+
526+
}
513527
}
514528
}
515529

0 commit comments

Comments
 (0)