@@ -11,13 +11,12 @@ use anyhow;
1111use autometrics:: prometheus_exporter;
1212use axum:: extract:: MatchedPath ;
1313use axum:: http:: Request ;
14+ use axum:: serve;
1415use axum:: {
1516 async_trait,
16- body:: Body ,
17- error_handling:: HandleErrorLayer ,
1817 response:: { IntoResponse , Response } ,
1918 routing:: { get, post} ,
20- BoxError , Extension , Json , Router , Server ,
19+ Extension , Json , Router ,
2120} ;
2221use build_info:: BuildInfo ;
2322use eventuals:: Eventual ;
@@ -28,9 +27,9 @@ use tap_core::{manager::Manager, receipt::checks::Checks};
2827use thegraph:: types:: Address ;
2928use thegraph:: types:: { Attestation , DeploymentId } ;
3029use thiserror:: Error ;
30+ use tokio:: net:: TcpListener ;
3131use tokio:: signal;
32- use tower:: ServiceBuilder ;
33- use tower_governor:: { errors:: display_error, governor:: GovernorConfigBuilder , GovernorLayer } ;
32+ use tower_governor:: { governor:: GovernorConfigBuilder , GovernorLayer } ;
3433use tower_http:: trace:: TraceLayer ;
3534use tracing:: { info, info_span} ;
3635
@@ -167,7 +166,7 @@ where
167166 pub release : IndexerServiceRelease ,
168167 pub url_namespace : & ' static str ,
169168 pub metrics_prefix : & ' static str ,
170- pub extra_routes : Router < Arc < IndexerServiceState < I > > , Body > ,
169+ pub extra_routes : Router < Arc < IndexerServiceState < I > > > ,
171170}
172171
173172pub struct IndexerServiceState < I >
@@ -329,13 +328,7 @@ impl IndexerService {
329328 . route ( "/" , get ( "Service is up and running" ) )
330329 . route ( "/version" , get ( Json ( options. release ) ) )
331330 . route ( "/info" , get ( operator_address) )
332- . layer (
333- ServiceBuilder :: new ( )
334- . layer ( HandleErrorLayer :: new ( |e : BoxError | async move {
335- display_error ( e)
336- } ) )
337- . layer ( misc_rate_limiter) ,
338- ) ;
331+ . layer ( misc_rate_limiter) ;
339332
340333 // Rate limits by allowing bursts of 50 requests and requiring 20ms of
341334 // time between consecutive requests after that, effectively rate
@@ -360,13 +353,7 @@ impl IndexerService {
360353 . route_layer ( Extension (
361354 options. config . network_subgraph . serve_auth_token . clone ( ) ,
362355 ) )
363- . route_layer (
364- ServiceBuilder :: new ( )
365- . layer ( HandleErrorLayer :: new ( |e : BoxError | async move {
366- display_error ( e)
367- } ) )
368- . layer ( static_subgraph_rate_limiter. clone ( ) ) ,
369- ) ,
356+ . route_layer ( static_subgraph_rate_limiter. clone ( ) ) ,
370357 ) ;
371358 }
372359
@@ -379,13 +366,7 @@ impl IndexerService {
379366 . route_layer ( Extension (
380367 options. config . escrow_subgraph . serve_auth_token . clone ( ) ,
381368 ) )
382- . route_layer (
383- ServiceBuilder :: new ( )
384- . layer ( HandleErrorLayer :: new ( |e : BoxError | async move {
385- display_error ( e)
386- } ) )
387- . layer ( static_subgraph_rate_limiter) ,
388- ) ;
369+ . route_layer ( static_subgraph_rate_limiter) ;
389370 }
390371
391372 misc_routes = misc_routes. with_state ( state. clone ( ) ) ;
@@ -435,11 +416,16 @@ impl IndexerService {
435416 address = %options. config. server. host_and_port,
436417 "Serving requests" ,
437418 ) ;
419+ let listener = TcpListener :: bind ( & options. config . server . host_and_port )
420+ . await
421+ . expect ( "Failed to bind to indexer-service port" ) ;
438422
439- Ok ( Server :: bind ( & options. config . server . host_and_port )
440- . serve ( router. into_make_service_with_connect_info :: < SocketAddr > ( ) )
441- . with_graceful_shutdown ( shutdown_signal ( ) )
442- . await ?)
423+ Ok ( serve (
424+ listener,
425+ router. into_make_service_with_connect_info :: < SocketAddr > ( ) ,
426+ )
427+ . with_graceful_shutdown ( shutdown_signal ( ) )
428+ . await ?)
443429 }
444430
445431 fn serve_metrics ( host_and_port : SocketAddr ) {
@@ -451,10 +437,14 @@ impl IndexerService {
451437 get ( || async { prometheus_exporter:: encode_http_response ( ) } ) ,
452438 ) ;
453439
454- Server :: bind ( & host_and_port)
455- . serve ( router. into_make_service ( ) )
456- . await
457- . expect ( "Failed to serve metrics" )
440+ serve (
441+ TcpListener :: bind ( host_and_port)
442+ . await
443+ . expect ( "Failed to bind to metrics port" ) ,
444+ router. into_make_service ( ) ,
445+ )
446+ . await
447+ . expect ( "Failed to serve metrics" )
458448 } ) ;
459449 }
460450}
0 commit comments