Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check-then-act race condition #1284

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hyper_cgi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "hyper_cgi"
version = "22.10.25"
authors = ["Christian Schilling <[email protected]>", "Louis-Marie Givel <[email protected]>"]
edition = "2018"
edition = "2021"
license-file = "LICENSE"
description = "Run CGI scripts with hyper"
repository = "https://github.com/josh-project/josh"
Expand Down
2 changes: 1 addition & 1 deletion josh-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license-file = "LICENSE"
description = "GIT virtualization proxy"
keywords = ["git", "monorepo", "workflow", "scm"]
readme = "README.md"
edition = "2018"
edition = "2021"

[dependencies]
backtrace = "0.3.69"
Expand Down
2 changes: 1 addition & 1 deletion josh-filter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Christian Schilling <[email protected]>"]
description = "GIT filter cli"
edition = "2018"
edition = "2021"
keywords = ["git", "monorepo", "workflow", "scm"]
license-file = "LICENSE"
name = "josh-filter"
Expand Down
2 changes: 1 addition & 1 deletion josh-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Christian Schilling <[email protected]>"]
description = "GIT virtualization proxy"
edition = "2018"
edition = "2021"
keywords = ["git", "monorepo", "workflow", "scm"]
license-file = "LICENSE"
name = "josh-proxy"
Expand Down
17 changes: 9 additions & 8 deletions josh-proxy/src/bin/josh-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ async fn fetch_upstream(

let refs_to_fetch: Vec<_> = refs_to_fetch.iter().map(|x| x.to_string()).collect();

let us = upstream_repo.clone();
let semaphore = service
.fetch_permits
.lock()?
.entry(us.clone())
.or_insert(Arc::new(tokio::sync::Semaphore::new(1)))
.clone();
let permit = semaphore.acquire().await;

let fetch_timer_ok = {
if let Some(last) = service.fetch_timers.read()?.get(&key) {
let since = std::time::Instant::now().duration_since(*last);
Expand Down Expand Up @@ -183,15 +192,7 @@ async fn fetch_upstream(
let br_path = service.repo_path.join("mirror");

let span = tracing::span!(tracing::Level::TRACE, "fetch worker");
let us = upstream_repo.clone();
let ru = remote_url.clone();
let semaphore = service
.fetch_permits
.lock()?
.entry(us.clone())
.or_insert(Arc::new(tokio::sync::Semaphore::new(1)))
.clone();
let permit = semaphore.acquire().await;
let task_remote_auth = remote_auth.clone();
let fetch_result = tokio::task::spawn_blocking(move || {
let _span_guard = span.enter();
Expand Down
1 change: 0 additions & 1 deletion josh-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ fn create_repo_base(path: &PathBuf) -> josh::JoshResult<josh::shell::Shell> {
.cloned()
.try_for_each(|(key, value)| -> JoshResult<()> {
use gix::config::parse::section::Key;
use std::convert::TryFrom;

let key = Key::try_from(key)
.map_err(|_| josh_error("unable to create config section"))?;
Expand Down
2 changes: 1 addition & 1 deletion josh-rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "josh-rpc"
version = "0.1.0"
edition = "2018"
edition = "2021"

[dependencies]
serde = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion josh-ssh-shell/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "josh-ssh-shell"
version = "0.1.0"
edition = "2018"
edition = "2021"

[dependencies]
clap = { workspace = true }
Expand Down
Loading