Clean up all requests after serving resume requests

Requests are not intended to be served out of order. fxrunner must only
send a single new request followed by a corresponding resume request. We
now clean up the request directory after each resume request.
This commit is contained in:
Barret Rennie 2020-07-15 21:56:50 -04:00
Родитель f2d656a851
Коммит f284398f87
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4D71D86C09132D72
1 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -3,6 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/. // file, You can obtain one at https://mozilla.org/MPL/2.0/.
use std::error::Error; use std::error::Error;
use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::Duration; use std::time::Duration;
@ -12,7 +13,7 @@ use libfxrunner::osapi::{WindowsPerfProvider, WindowsShutdownProvider};
use libfxrunner::proto::RunnerProto; use libfxrunner::proto::RunnerProto;
use libfxrunner::request::FsRequestManager; use libfxrunner::request::FsRequestManager;
use libfxrunner::taskcluster::FirefoxCi; use libfxrunner::taskcluster::FirefoxCi;
use slog::{error, info, Logger}; use slog::{error, info, warn, Logger};
use structopt::StructOpt; use structopt::StructOpt;
use tokio::fs::create_dir_all; use tokio::fs::create_dir_all;
use tokio::net::TcpListener; use tokio::net::TcpListener;
@ -96,6 +97,13 @@ async fn fxrunner(log: Logger, options: Options, config: Config) -> Result<(), B
} }
info!(log, "Client disconnected"); info!(log, "Client disconnected");
// We aren't restarting, which means we handled a resume request. We
// only expect a single pending request at a time, so the request
// directory *should* be empty. If it isn't, then isn't empty it.
if let Err(e) = cleanup_requests_dir(log.clone(), &config.requests_dir).await {
error!(log, "Could not cleanup requests directory"; "error" => ?e);
}
} }
info!(log, "Client disconnected for restart"); info!(log, "Client disconnected for restart");
@ -128,3 +136,15 @@ fn shutdown_provider(options: &Options) -> WindowsShutdownProvider {
fn shutdown_provider(_: &Options) -> WindowsShutdownProvider { fn shutdown_provider(_: &Options) -> WindowsShutdownProvider {
WindowsShutdownProvider::default() WindowsShutdownProvider::default()
} }
async fn cleanup_requests_dir(log: slog::Logger, path: &Path) -> Result<(), io::Error> {
let mut entries = tokio::fs::read_dir(path).await?;
while let Some(entry) = entries.next_entry().await? {
let path = entry.path();
warn!(log, "requests directory was not empty"; "path" => path.display());
tokio::fs::remove_dir_all(&path).await?;
}
Ok(())
}