@@ -44,6 +44,7 @@ type CustomRetryPolicy = FilteredRetryPolicy<
4444> ;
4545
4646const INTERNAL_RUNTIME_WORKERS : usize = 2 ;
47+ const VSS_IO_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
4748
4849/// A [`KVStoreSync`] implementation that writes to and reads from a [VSS](https://github.com/lightningdevkit/vss-server/blob/main/README.md) backend.
4950pub struct VssStore {
@@ -120,7 +121,14 @@ impl KVStoreSync for VssStore {
120121 let inner = Arc :: clone ( & self . inner ) ;
121122 let fut =
122123 async move { inner. read_internal ( primary_namespace, secondary_namespace, key) . await } ;
123- tokio:: task:: block_in_place ( move || internal_runtime. block_on ( fut) )
124+ let spawned_fut = internal_runtime. spawn ( async move {
125+ tokio:: time:: timeout ( VSS_IO_TIMEOUT , fut) . await . map_err ( |_| {
126+ let msg = "VssStore::read timed out" ;
127+ Error :: new ( ErrorKind :: Other , msg)
128+ } )
129+ } ) ;
130+ tokio:: task:: block_in_place ( move || internal_runtime. block_on ( spawned_fut) )
131+ . expect ( "We should always finish" ) ?
124132 }
125133
126134 fn write (
@@ -150,7 +158,14 @@ impl KVStoreSync for VssStore {
150158 )
151159 . await
152160 } ;
153- tokio:: task:: block_in_place ( move || internal_runtime. block_on ( fut) )
161+ let spawned_fut = internal_runtime. spawn ( async move {
162+ tokio:: time:: timeout ( VSS_IO_TIMEOUT , fut) . await . map_err ( |_| {
163+ let msg = "VssStore::write timed out" ;
164+ Error :: new ( ErrorKind :: Other , msg)
165+ } )
166+ } ) ;
167+ tokio:: task:: block_in_place ( move || internal_runtime. block_on ( spawned_fut) )
168+ . expect ( "We should always finish" ) ?
154169 }
155170
156171 fn remove (
@@ -179,7 +194,14 @@ impl KVStoreSync for VssStore {
179194 )
180195 . await
181196 } ;
182- tokio:: task:: block_in_place ( move || internal_runtime. block_on ( fut) )
197+ let spawned_fut = internal_runtime. spawn ( async move {
198+ tokio:: time:: timeout ( VSS_IO_TIMEOUT , fut) . await . map_err ( |_| {
199+ let msg = "VssStore::remove timed out" ;
200+ Error :: new ( ErrorKind :: Other , msg)
201+ } )
202+ } ) ;
203+ tokio:: task:: block_in_place ( move || internal_runtime. block_on ( spawned_fut) )
204+ . expect ( "We should always finish" ) ?
183205 }
184206
185207 fn list ( & self , primary_namespace : & str , secondary_namespace : & str ) -> io:: Result < Vec < String > > {
@@ -192,7 +214,14 @@ impl KVStoreSync for VssStore {
192214 let secondary_namespace = secondary_namespace. to_string ( ) ;
193215 let inner = Arc :: clone ( & self . inner ) ;
194216 let fut = async move { inner. list_internal ( primary_namespace, secondary_namespace) . await } ;
195- tokio:: task:: block_in_place ( move || internal_runtime. block_on ( fut) )
217+ let spawned_fut = internal_runtime. spawn ( async move {
218+ tokio:: time:: timeout ( VSS_IO_TIMEOUT , fut) . await . map_err ( |_| {
219+ let msg = "VssStore::list timed out" ;
220+ Error :: new ( ErrorKind :: Other , msg)
221+ } )
222+ } ) ;
223+ tokio:: task:: block_in_place ( move || internal_runtime. block_on ( spawned_fut) )
224+ . expect ( "We should always finish" ) ?
196225 }
197226}
198227
0 commit comments