| 1 | package edu.ucsb.cs156.courses.config; | |
| 2 | ||
| 3 | import java.util.concurrent.TimeUnit; | |
| 4 | import org.springframework.beans.factory.annotation.Value; | |
| 5 | import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer; | |
| 6 | import org.springframework.context.annotation.Bean; | |
| 7 | import org.springframework.context.annotation.Configuration; | |
| 8 | ||
| 9 | /** | |
| 10 | * Limits how long the MongoDB driver waits for a usable server before giving up. | |
| 11 | * | |
| 12 | * <p>The driver's default is 30 seconds. When MongoDB is unreachable, that makes every request that | |
| 13 | * touches MongoDB hang for 30 seconds before failing, including the health check at | |
| 14 | * /api/actuator/health, which every open browser tab polls once a minute, and which an uptime | |
| 15 | * monitor may give up on before it answers. See docs/healthcheck.md. | |
| 16 | * | |
| 17 | * <p>When MongoDB is healthy this wait is never used, so a short value costs nothing. | |
| 18 | */ | |
| 19 | @Configuration | |
| 20 | public class MongoTimeoutConfig { | |
| 21 | ||
| 22 | @Bean | |
| 23 | public MongoClientSettingsBuilderCustomizer mongoServerSelectionTimeout( | |
| 24 | @Value("${app.mongo.serverSelectionTimeoutSeconds:5}") int seconds) { | |
| 25 |
1
1. mongoServerSelectionTimeout : replaced return value with null for edu/ucsb/cs156/courses/config/MongoTimeoutConfig::mongoServerSelectionTimeout → KILLED |
return builder -> |
| 26 | builder.applyToClusterSettings( | |
| 27 | cluster -> cluster.serverSelectionTimeout(seconds, TimeUnit.SECONDS)); | |
| 28 | } | |
| 29 | } | |
Mutations | ||
| 25 |
1.1 |