Skip to content

Commit eee3d46

Browse files
committed
fix(snix/store): don't spawn tokio tasks in RedbPathInfoService.list
Fixes a panic in `list` impl of PathInfoService for fuse/virtiofs: ``` thread 'vring_worker' panicked at store/src/pathinfoservice/redb.rs:136:9: there is no reactor running, must be called from the context of a Tokio 1.x runtime ``` Closes #147. Change-Id: I2bed5157b30fa185276dcaefd35277159a01fe2d Reviewed-on: https://cl.snix.dev/c/snix/+/30575 Reviewed-by: Florian Klink <flokli@flokli.de> Tested-by: besadii
1 parent 3f5715f commit eee3d46

File tree

1 file changed

+20
-31
lines changed
  • snix/store/src/pathinfoservice

1 file changed

+20
-31
lines changed

snix/store/src/pathinfoservice/redb.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use super::{PathInfo, PathInfoService};
22
use crate::proto;
3+
use async_stream::try_stream;
34
use data_encoding::BASE64;
4-
use futures::{StreamExt, stream::BoxStream};
5+
use futures::stream::BoxStream;
56
use prost::Message;
67
use redb::{Database, ReadableTable, TableDefinition};
78
use snix_castore::{
89
Error,
910
composition::{CompositionContext, ServiceBuilder},
1011
};
1112
use std::{path::PathBuf, sync::Arc};
12-
use tokio_stream::wrappers::ReceiverStream;
1313
use tonic::async_trait;
1414
use tracing::{instrument, warn};
1515

@@ -130,37 +130,26 @@ impl PathInfoService for RedbPathInfoService {
130130

131131
fn list(&self) -> BoxStream<'static, Result<PathInfo, Error>> {
132132
let db = self.db.clone();
133-
let (tx, rx) = tokio::sync::mpsc::channel(50);
134-
135-
// Spawn a blocking task which writes all PathInfos to tx.
136-
tokio::task::spawn_blocking({
137-
move || -> Result<(), Error> {
138-
let read_txn = db.begin_read()?;
139-
let table = read_txn.open_table(PATHINFO_TABLE)?;
140-
141-
for elem in table.iter()? {
142-
let elem = elem?;
143-
tokio::runtime::Handle::current()
144-
.block_on(tx.send(Ok({
145-
let path_info_proto = proto::PathInfo::decode(
146-
elem.1.value().as_slice(),
147-
)
148-
.map_err(|e| {
149-
warn!(err=%e, "invalid PathInfo");
150-
Error::StorageError("invalid PathInfo".to_string())
151-
})?;
152-
PathInfo::try_from(path_info_proto).map_err(|e| {
153-
Error::StorageError(format!("Invalid path info: {e}"))
154-
})?
155-
})))
156-
.map_err(|e| Error::StorageError(e.to_string()))?;
133+
Box::pin(try_stream! {
134+
let read_txn = db.begin_read()?;
135+
let table = read_txn.open_table(PATHINFO_TABLE)?;
136+
137+
for elem in table.iter()? {
138+
let elem = elem?;
139+
yield {
140+
let path_info_proto = proto::PathInfo::decode(
141+
elem.1.value().as_slice(),
142+
)
143+
.map_err(|e| {
144+
warn!(err=%e, "invalid PathInfo");
145+
Error::StorageError("invalid PathInfo".to_string())
146+
})?;
147+
PathInfo::try_from(path_info_proto).map_err(|e| {
148+
Error::StorageError(format!("Invalid path info: {e}"))
149+
})?
157150
}
158-
159-
Ok(())
160151
}
161-
});
162-
163-
ReceiverStream::from(rx).boxed()
152+
})
164153
}
165154
}
166155

0 commit comments

Comments
 (0)