Avoid timeout with >= 1 billion nsecs
Registering a timeout of >= 1000 msecs produced an error message,
but still resulted in a system call with timeout nsecs >= 1 billion,
which would cause an error return from the system call and a crash.
Avoid this by restricting timeouts to the maximum. Also enforce
minimum for symmetry.
Bug: 140968481
Test: TreeHugger
Change-Id: I191fb88a03bf09d2c5a93864bb26624c10b6e52d
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 5343150..38f8ce1 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1418,9 +1418,13 @@
monitor_timeout_enable_ = runtime_options.GetOrDefault(Opt::MonitorTimeoutEnable);
int monitor_timeout_ms = runtime_options.GetOrDefault(Opt::MonitorTimeout);
- if (monitor_timeout_ms < Monitor::kMonitorTimeoutMinMs ||
- monitor_timeout_ms >= Monitor::kMonitorTimeoutMaxMs) {
- LOG(ERROR) << "Improper monitor timeout could cause crash!";
+ if (monitor_timeout_ms < Monitor::kMonitorTimeoutMinMs) {
+ LOG(WARNING) << "Monitor timeout too short: Increasing";
+ monitor_timeout_ms = Monitor::kMonitorTimeoutMinMs;
+ }
+ if (monitor_timeout_ms >= Monitor::kMonitorTimeoutMaxMs) {
+ LOG(WARNING) << "Monitor timeout too long: Decreasing";
+ monitor_timeout_ms = Monitor::kMonitorTimeoutMaxMs - 1;
}
monitor_timeout_ns_ = MsToNs(monitor_timeout_ms);