Allow application to start even if connection fails
See original GitHub issueWhich version and edition of Flyway are you using?
7.4.0
If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)
Yes I can.
Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)
Quarkus
Which database are you using? (Type & version)
Postgres 10
Which operating system are you using?
Linux, MacOS and Windows
What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)
I’m writing a healthcheck to my app and I want it to go up even if Flyway fails to connect upon application start. In other words, I’m using the “5 minutes tutorial” to run an create an application, then I turned I pointed the DB to an invalid address and tried to start the application.
What did you expect to see?
I expected to have an option to tell flyway to give a warning or something that would tell me it wasn’t able to connect, instead of plain System.exit(1)
.
Something like:
// org.flywaydb.core.Flyway#execute (line ~542 at master)
// ...
this.failedState = false;
// extracted it to a method to make it prettier
result = doDatabaseExecution(all_the_necessary_parameters);
}
private <T> T createDatabase(all_the_necessary_parameters<T>) {
Database database = null;
try {
// copy lines 544 through 580
} catch (DataBaseConnectionException e) { // specific exception for said problem
if (configuration.isFailOnDatabaseConnection) { // default = true
throw e;
}
LOG.error("Unable to connect to database in order to run migrations. Moving to failed state.", e);
this.failedState = true;
} finally {
IOUtils.close(database);
showMemoryUsage();
}
// ...
What did you see instead?
What I got was the default behaviour, which tries to connect and kills the application in case of errors.
I’ll post a pull request later on.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
How to make Spring server to start even if database is down?
You can set: spring.sql.init.continue-on-error=true. in your application.properties. According to the Spring Boot 2.5.5 user guide:.
Read more >Allow an app to start when its DataSource is unable to connect ...
I stumbled about this behaviour when I tried to start a Spring Boot application along with a database via Docker Compose. The Docker ......
Read more >Executing Code on Spring Boot Application Startup
Spring Boot offers many different solutions to run code at application startup. This article explains how they work and when to use which....
Read more >Top 10 Most Common Spring Framework Mistakes - Toptal
In this article we'll cover some of the more common mistakes in Spring, specifically oriented towards web applications and Spring Boot. As Spring...
Read more >How to perform a clean boot in Windows - Microsoft Support
A "clean boot" starts Windows with a minimal set of drivers and startup programs, so that you can determine whether a background program...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As the Rubber Duck Theory comes into practice while I explain this issue to you, it just made me realize that it might not be a Flyway issue, after all. It seems like Quarkus is killing the application if the connection fails.
Mikiel, I’ll go ahead and close this issue.
Despite Flyway being the one that threw the exception, Quarkus itself was the one responsible for terminating the application.
In the end, I had to switch Flyway to run manually inside a bean associated with Quarkus’ application lifecycle Startup phase.
Here’s a sample:
I also had to set
quarkus.flyway.migrate-at-start=false
atapplication.properties
in order to preventio.quarkus.flyway.FlywayProcessor
from running the integration automatically before my managed bean.It would be nice to extend
FlywaySqlException
into aFlywaySqlConnectionException
in order to handle it in different ways, though.Thanks for waiting.