Skip to content

graph: Log the path we are accessing in IPFS errors #6032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 49 additions & 47 deletions graph/src/ipfs/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ use crate::ipfs::ContentPath;
use crate::ipfs::IpfsError;
use crate::ipfs::IpfsResult;
use crate::ipfs::RetryPolicy;
use crate::util::futures::RetryConfigNoTimeout;

fn retry_no_timeout<O: Send + Sync + 'static>(
retry_policy: RetryPolicy,
opname: &str,
logger: &Logger,
path: &ContentPath,
) -> RetryConfigNoTimeout<O, IpfsError> {
let logger = logger.new(slog::o!("path" => path.to_string()));
retry_policy.create(opname, &logger).no_timeout()
}

/// A read-only connection to an IPFS server.
#[async_trait]
Expand All @@ -36,19 +47,16 @@ pub trait IpfsClient: Send + Sync + 'static {
timeout: Option<Duration>,
retry_policy: RetryPolicy,
) -> IpfsResult<BoxStream<'static, IpfsResult<Bytes>>> {
let fut = retry_policy
.create("IPFS.cat_stream", self.logger())
.no_timeout()
.run({
let path = path.to_owned();
let fut = retry_no_timeout(retry_policy, "IPFS.cat_stream", self.logger(), path).run({
let path = path.to_owned();

move || {
let path = path.clone();
let client = self.clone();
move || {
let path = path.clone();
let client = self.clone();

async move { client.call(IpfsRequest::Cat(path)).await }
}
});
async move { client.call(IpfsRequest::Cat(path)).await }
}
});

let resp = run_with_optional_timeout(path, fut, timeout).await?;

Expand All @@ -66,25 +74,22 @@ pub trait IpfsClient: Send + Sync + 'static {
timeout: Option<Duration>,
retry_policy: RetryPolicy,
) -> IpfsResult<Bytes> {
let fut = retry_policy
.create("IPFS.cat", self.logger())
.no_timeout()
.run({
let path = path.to_owned();

move || {
let path = path.clone();
let client = self.clone();

async move {
client
.call(IpfsRequest::Cat(path))
.await?
.bytes(Some(max_size))
.await
}
let fut = retry_no_timeout(retry_policy, "IPFS.cat", self.logger(), path).run({
let path = path.to_owned();

move || {
let path = path.clone();
let client = self.clone();

async move {
client
.call(IpfsRequest::Cat(path))
.await?
.bytes(Some(max_size))
.await
}
});
}
});

run_with_optional_timeout(path, fut, timeout).await
}
Expand All @@ -99,25 +104,22 @@ pub trait IpfsClient: Send + Sync + 'static {
timeout: Option<Duration>,
retry_policy: RetryPolicy,
) -> IpfsResult<Bytes> {
let fut = retry_policy
.create("IPFS.get_block", self.logger())
.no_timeout()
.run({
let path = path.to_owned();

move || {
let path = path.clone();
let client = self.clone();

async move {
client
.call(IpfsRequest::GetBlock(path))
.await?
.bytes(None)
.await
}
let fut = retry_no_timeout(retry_policy, "IPFS.get_block", self.logger(), path).run({
let path = path.to_owned();

move || {
let path = path.clone();
let client = self.clone();

async move {
client
.call(IpfsRequest::GetBlock(path))
.await?
.bytes(None)
.await
}
});
}
});

run_with_optional_timeout(path, fut, timeout).await
}
Expand Down
Loading