Skip to content
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

test(fix): interop UnixFS-chunked JSON file #56

Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/interop/src/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('@helia/verified-fetch - json', () => {
await loadFixtureDataCar(controller, 'QmQJ8fxavY54CUsxMSx9aE9Rdcmvhx8awJK2jzJp4iAqCr-tokens.uniswap.org-2024-01-18.car')
verifiedFetch = await createVerifiedFetch({
gateways: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`],
routers: [`http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`]
routers: []
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp fix to stop endless routing caused by ipfs/helia#501

})
})

Expand Down
17 changes: 14 additions & 3 deletions packages/verified-fetch/src/utils/walk-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ export async function walkPath (blockstore: ReadableStorage, path: string, optio
const ipfsRoots: CID[] = []
let terminalElement: UnixFSEntry | undefined

for await (const entry of exporterWalk(path, blockstore, options)) {
ipfsRoots.push(entry.cid)
terminalElement = entry
try {
for await (const entry of exporterWalk(path, blockstore, options)) {
ipfsRoots.push(entry.cid)
terminalElement = entry
}
} catch (err: any) {
if (err.errors?.length > 0) {
for (const error of err.errors) {
if (error.code === 'ERR_NO_ROUTERS_AVAILABLE') {
throw error
}
}
}
throw err
}

if (terminalElement == null) {
Expand Down
28 changes: 22 additions & 6 deletions packages/verified-fetch/src/verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,19 @@ export class VerifiedFetch {
return this.helia.blockstore
}

let session = this.blockstoreSessions.get(key)
try {
let session = this.blockstoreSessions.get(key)

if (session == null) {
session = this.helia.blockstore.createSession(root, options)
this.blockstoreSessions.set(key, session)
}
if (session == null) {
session = this.helia.blockstore.createSession(root, options)
this.blockstoreSessions.set(key, session)
}

return session
return session
} catch (e) {
this.log.error('error creating blockstore session', e)
return this.helia.blockstore
}
}

/**
Expand Down Expand Up @@ -289,6 +294,11 @@ export class VerifiedFetch {
if (['ERR_NO_PROP', 'ERR_NO_TERMINAL_ELEMENT'].includes(err.code)) {
return notFoundResponse(resource)
}
if (err.code === 'ERR_NO_ROUTERS_AVAILABLE') {
// need to retry without sessions
// TODO: handle this better
return this.handleDagCbor({ resource, cid, path, accept, session: false, cacheKey, options })
}
Comment on lines +297 to +301
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, there is no way to check this.helia.routing for routers length? feels like this should be handled in helia session management code


this.log.error('error walking path %s', path, err)
return badGatewayResponse(resource, 'Error walking path')
Expand Down Expand Up @@ -357,6 +367,12 @@ export class VerifiedFetch {
if (['ERR_NO_PROP', 'ERR_NO_TERMINAL_ELEMENT'].includes(err.code)) {
return notFoundResponse(resource.toString())
}

if (err.code === 'ERR_NO_ROUTERS_AVAILABLE') {
// need to retry without sessions
// TODO: handle this better
return this.handleDagPb({ resource, cid, path, cacheKey, session: false, options })
}
this.log.error('error walking path %s', path, err)

return badGatewayResponse(resource.toString(), 'Error walking path')
Expand Down
Loading