@@ -727,7 +727,7 @@ struct IsUpdating(Arc<AtomicBool>);
727
727
728
728
impl Drop for IsUpdating {
729
729
fn drop ( & mut self ) {
730
- self . 0 . store ( false , AtomicOrdering :: Release ) ;
730
+ self . 0 . store ( false , AtomicOrdering :: SeqCst ) ;
731
731
}
732
732
}
733
733
@@ -738,7 +738,11 @@ impl UpdatingStatus {
738
738
739
739
// Returns previous state
740
740
fn set_updating ( & self ) -> bool {
741
- self . 0 . compare_and_swap ( false , true , AtomicOrdering :: AcqRel )
741
+ self . 0 . compare_and_swap ( false , true , AtomicOrdering :: SeqCst )
742
+ }
743
+
744
+ fn is_updating ( & self ) -> bool {
745
+ self . 0 . load ( AtomicOrdering :: SeqCst )
742
746
}
743
747
744
748
fn release_on_drop ( & self ) -> IsUpdating {
@@ -830,21 +834,20 @@ impl Server {
830
834
let updating = self . updating . release_on_drop ( ) ;
831
835
let _ = std:: thread:: spawn ( move || {
832
836
let repo_path = get_repo_path ( ) . unwrap ( ) ;
833
-
834
837
git:: update_repo ( & repo_path) . unwrap ( ) ;
835
838
839
+ // Acquire the lock. We're not returning data via HTTP already anyway, as we've cleared
840
+ let mut handle = rwlock. write ( ) ;
841
+
836
842
// Erase old data
837
- * rwlock . write ( ) = None ;
843
+ * handle = None ;
838
844
839
845
info ! ( "updating from filesystem..." ) ;
840
846
let new_data = Arc :: new ( InputData :: from_fs ( & repo_path) . unwrap ( ) ) ;
841
847
debug ! ( "last date = {:?}" , new_data. last_date) ;
842
848
843
- // Retrieve the stored InputData from the request.
844
- let mut data = rwlock. write ( ) ;
845
-
846
849
// Write the new data back into the request
847
- * data = Some ( new_data) ;
850
+ * handle = Some ( new_data) ;
848
851
849
852
std:: mem:: drop ( updating) ;
850
853
} ) ;
@@ -865,7 +868,8 @@ impl fmt::Display for ServerError {
865
868
impl std:: error:: Error for ServerError { }
866
869
867
870
async fn serve_req ( ctx : Arc < Server > , req : Request ) -> Result < Response , ServerError > {
868
- if ctx. data . read ( ) . is_none ( ) {
871
+ // Don't attempt to get lock if we're updating
872
+ if ctx. updating . is_updating ( ) || ctx. data . read ( ) . is_none ( ) {
869
873
return Ok ( Response :: new ( hyper:: Body :: from ( "no data yet, please wait" ) ) ) ;
870
874
}
871
875
0 commit comments