Skip to content

Commit a9566d7

Browse files
mzrfacebook-github-bot
authored andcommitted
send empty bundle-list upon failure
Summary: When we fail to generate a bundle-list, the whole git command fails, but when we send an empty bundle list, nothing happens - git just sees it's empty and does nothing. In case of a sever-side failure, let's just fail silently and send an empty bundle-list to the client. When we fail silently we have to log it, otherwise there's no way of knowing we're failing, so I'm also adding logging here. Reviewed By: RajivTS Differential Revision: D73188354 fbshipit-source-id: ebc80c2a2b423e640fe175d4c8b067b9cc7db9d7
1 parent ed6c859 commit a9566d7

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

eden/mononoke/git_server/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(never_type)]
1010
#![feature(let_chains)]
1111
#![feature(cursor_split)]
12+
#![feature(try_blocks)]
1213

1314
use std::fs::File;
1415
use std::io::Write;

eden/mononoke/git_server/src/model.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use context::GitServerContext;
1313
pub use context::RepositoryRequestContext;
1414
use gotham_derive::StateData;
1515
use gotham_derive::StaticResponseExtender;
16+
pub use method::BundleUriOutcome;
1617
pub use method::GitMethod;
1718
pub use method::GitMethodInfo;
1819
pub use method::PushValidationErrors;

eden/mononoke/git_server/src/model/method.rs

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ impl Display for PushValidationErrors {
180180
}
181181
}
182182

183+
#[derive(Clone, StateData)]
184+
pub enum BundleUriOutcome {
185+
Success(String),
186+
Error(String),
187+
}
188+
183189
#[cfg(test)]
184190
mod tests {
185191
use anyhow::Result;

eden/mononoke/git_server/src/read/upload_pack.rs

+35-7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use crate::command::Command;
6262
use crate::command::FetchArgs;
6363
use crate::command::LsRefsArgs;
6464
use crate::command::RequestCommand;
65+
use crate::model::BundleUriOutcome;
6566
use crate::model::GitMethodInfo;
6667
use crate::model::RepositoryParams;
6768
use crate::model::RepositoryRequestContext;
@@ -339,7 +340,7 @@ pub async fn upload_pack(state: &mut State) -> Result<Response<Body>, HttpError>
339340
}
340341
Command::BundleUri => {
341342
let git_host = GitHost::from_state_mononoke_host(state)?;
342-
let output = bundle_uri(&request_context, git_host).await;
343+
let output = bundle_uri(state, &request_context, git_host).await;
343344
let output = output.map_err(HttpError::e500)?.try_into_response(state);
344345
output.map_err(HttpError::e500)
345346
}
@@ -350,6 +351,7 @@ pub async fn upload_pack(state: &mut State) -> Result<Response<Body>, HttpError>
350351
}
351352

352353
async fn bundle_uri(
354+
state: &mut State,
353355
request_context: &RepositoryRequestContext,
354356
git_host: GitHost,
355357
) -> Result<impl TryIntoResponse, Error> {
@@ -360,15 +362,41 @@ async fn bundle_uri(
360362
let bundle_list = bundle_uri.get_latest_bundle_list().await?;
361363

362364
if let Some(bundle_list) = bundle_list {
363-
for bundle in bundle_list.bundles.iter() {
364-
let uri = bundle_uri
365-
.get_url_for_bundle_handle(&request_context.ctx, &git_host, 60, &bundle.handle)
366-
.await?;
365+
let bundle_list_out: Result<Vec<u8>, anyhow::Error> = try {
366+
let mut bundle_list_out_buf: Vec<u8> = vec![];
367+
for bundle in bundle_list.bundles.iter() {
368+
let uri = bundle_uri
369+
.get_url_for_bundle_handle(
370+
&request_context.ctx,
371+
&git_host,
372+
60,
373+
&bundle.handle,
374+
)
375+
.await?;
367376

368-
let str = format!("\nbundle.bundle_{}.uri={}", bundle.fingerprint, uri,);
369-
out.extend_from_slice(str.as_bytes());
377+
let str = format!("\nbundle.bundle_{}.uri={}", bundle.fingerprint, uri,);
378+
bundle_list_out_buf.extend_from_slice(str.as_bytes());
379+
}
380+
bundle_list_out_buf
381+
};
382+
match bundle_list_out {
383+
Ok(blo) => {
384+
state.put(BundleUriOutcome::Success(format!(
385+
"advertised {} bundles from bundle list {}",
386+
bundle_list.bundles.len(),
387+
bundle_list.bundle_list_num
388+
)));
389+
out.extend_from_slice(&blo[..])
390+
}
391+
Err(err) => {
392+
state.put(BundleUriOutcome::Error(format!("{:?}", err)));
393+
}
370394
}
395+
} else {
396+
state.put(BundleUriOutcome::Success("bundle-list empty".to_string()));
371397
}
398+
} else {
399+
state.put(BundleUriOutcome::Success("client untrusted".to_string()));
372400
}
373401

374402
let mut output = Vec::new();

eden/mononoke/git_server/src/scuba.rs

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use gotham_ext::middleware::request_context::RequestContext;
1414
use permission_checker::MononokeIdentitySetExt;
1515
use scuba_ext::MononokeScubaSampleBuilder;
1616

17+
use crate::model::BundleUriOutcome;
1718
use crate::model::GitMethodInfo;
1819
use crate::model::PushValidationErrors;
1920

@@ -26,6 +27,8 @@ pub enum MononokeGitScubaKey {
2627
Error,
2728
ErrorCount,
2829
PushValidationErrors,
30+
BundleUriError,
31+
BundleUriSuccess,
2932
PackfileReadError,
3033
PackfileSize,
3134
PackfileCommitCount,
@@ -43,6 +46,8 @@ impl AsRef<str> for MononokeGitScubaKey {
4346
Self::Error => "error",
4447
Self::ErrorCount => "error_count",
4548
Self::PushValidationErrors => "push_validation_errors",
49+
Self::BundleUriError => "bundle_uri_error_msg",
50+
Self::BundleUriSuccess => "bundle_uri_success_msg",
4651
Self::PackfileReadError => "packfile_read_error",
4752
Self::PackfileSize => "packfile_size",
4853
Self::PackfileCommitCount => "packfile_commit_count",
@@ -63,6 +68,7 @@ pub struct MononokeGitScubaHandler {
6368
request_context: Option<RequestContext>,
6469
method_info: Option<GitMethodInfo>,
6570
push_validation_errors: Option<PushValidationErrors>,
71+
bundle_uri_outcome: Option<BundleUriOutcome>,
6672
client_username: Option<String>,
6773
}
6874

@@ -101,6 +107,7 @@ impl MononokeGitScubaHandler {
101107
Self {
102108
request_context: state.try_borrow::<RequestContext>().cloned(),
103109
method_info: state.try_borrow::<GitMethodInfo>().cloned(),
110+
bundle_uri_outcome: state.try_borrow::<BundleUriOutcome>().cloned(),
104111
push_validation_errors: state.try_borrow::<PushValidationErrors>().cloned(),
105112
client_username: state
106113
.try_borrow::<MetadataState>()
@@ -130,6 +137,16 @@ impl MononokeGitScubaHandler {
130137
push_validation_errors.to_string(),
131138
);
132139
}
140+
if let Some(outcome) = self.bundle_uri_outcome {
141+
match outcome {
142+
BundleUriOutcome::Success(success_msg) => {
143+
scuba.add(MononokeGitScubaKey::BundleUriSuccess, success_msg);
144+
}
145+
BundleUriOutcome::Error(error_msg) => {
146+
scuba.add(MononokeGitScubaKey::BundleUriError, error_msg);
147+
}
148+
}
149+
}
133150
if let Some(err) = info.first_error() {
134151
scuba.add(MononokeGitScubaKey::Error, format!("{:?}", err));
135152
}

0 commit comments

Comments
 (0)