@@ -53,6 +53,7 @@ use std::time::{
5353 Instant ,
5454} ;
5555use tempdir:: TempDir ;
56+ use tokio_core:: reactor:: { Handle , Timeout } ;
5657
5758use errors:: * ;
5859
@@ -174,6 +175,8 @@ pub enum MissType {
174175 Normal ,
175176 /// Cache lookup was overridden, recompilation was forced.
176177 ForcedRecache ,
178+ /// Cache took too long to respond.
179+ TimedOut ,
177180}
178181
179182/// Information about a successful cache write.
@@ -298,7 +301,8 @@ impl Compiler {
298301 parsed_args : & ParsedArguments ,
299302 cwd : & str ,
300303 cache_control : CacheControl ,
301- pool : & CpuPool )
304+ pool : & CpuPool ,
305+ handle : & Handle )
302306 -> SFuture < ( CompileResult , process:: Output ) >
303307 where T : CommandCreatorSync
304308 {
@@ -319,6 +323,7 @@ impl Compiler {
319323 let storage = storage. clone ( ) ;
320324 let pool = pool. clone ( ) ;
321325 let creator = creator. clone ( ) ;
326+ let handle = handle. clone ( ) ;
322327
323328 Box :: new ( result. and_then ( move |preprocessor_result| -> SFuture < _ > {
324329 // If the preprocessor failed, just return that result.
@@ -355,6 +360,20 @@ impl Compiler {
355360 storage. get ( & key)
356361 } ;
357362
363+ // Wait at most a minute for the cache to respond before we forge
364+ // ahead ourselves with a compilation.
365+ let timeout = Duration :: new ( 60 , 0 ) ;
366+ let timeout = Timeout :: new ( timeout, & handle) . into_future ( ) . flatten ( ) ;
367+
368+ let cache_status = cache_status. map ( Some ) ;
369+ let timeout = timeout. map ( |_| None ) . chain_err ( || "timeout error" ) ;
370+ let cache_status = cache_status. select ( timeout) . then ( |r| {
371+ match r {
372+ Ok ( ( a, _other) ) => Ok ( a) ,
373+ Err ( ( e, _other) ) => Err ( e) ,
374+ }
375+ } ) ;
376+
358377 Box :: new ( cache_status. and_then ( move |result| {
359378 let duration = start. elapsed ( ) ;
360379 let pwd = Path :: new ( & cwd) ;
@@ -363,7 +382,7 @@ impl Compiler {
363382 . collect :: < HashMap < _ , _ > > ( ) ;
364383
365384 let miss_type = match result {
366- Cache :: Hit ( mut entry) => {
385+ Some ( Cache :: Hit ( mut entry) ) => {
367386 debug ! ( "[{}]: Cache hit!" , parsed_args. output_file( ) ) ;
368387 let mut stdout = io:: Cursor :: new ( vec ! ( ) ) ;
369388 let mut stderr = io:: Cursor :: new ( vec ! ( ) ) ;
@@ -386,14 +405,18 @@ impl Compiler {
386405 ( result, output)
387406 } ) ) as SFuture < _ >
388407 }
389- Cache :: Miss => {
408+ Some ( Cache :: Miss ) => {
390409 debug ! ( "[{}]: Cache miss!" , parsed_args. output_file( ) ) ;
391410 MissType :: Normal
392411 }
393- Cache :: Recache => {
412+ Some ( Cache :: Recache ) => {
394413 debug ! ( "[{}]: Cache recache!" , parsed_args. output_file( ) ) ;
395414 MissType :: ForcedRecache
396415 }
416+ None => {
417+ debug ! ( "[{}]: Cache timed out!" , parsed_args. output_file( ) ) ;
418+ MissType :: TimedOut
419+ }
397420 } ;
398421 me. compile ( & creator,
399422 preprocessor_result,
0 commit comments