Skip to content

bug: trustless-gateway session edge-case #775

@SgtPooki

Description

@SgtPooki

i'm working on ipfs/service-worker-gateway#674

I've got code ready to go in the service worker, and can sometimes get things to abort properly.. however, one situation keeps coming up:

If a signal is aborted during getRawBlock, the session will stay alive forever:

helia:trustless-gateway:session:bafkreig7p6kzwgg4hp3n7wpnnn3kkjmpzxds5rmwhphyueilbzabvyexvq:error error querying provider TrustlessGateway { url: URL { href: 'http://127.0.0.1:55970/', origin: 'http://127.0.0.1:55970', protocol: 'http:', username: '', password: '', host: '127.0.0.1:55970', hostname: '127.0.0.1', port: '55970', pathname: '/', search: '', searchParams: URLSearchParams {}, hash: '' }, log: [Function: debug] { namespace: 'helia:trustless-gateway-block-broker:127.0.0.1', useColors: true, color: 32, extend: [Function: extend], destroy: [Function: destroy], enabled: [Getter/Setter], inspectOpts: {}, error: [Function: debug] { namespace: 'helia:trustless-gateway-block-broker:127.0.0.1:error', useColors: true, color: 166, extend: [Function: extend], destroy: [Function: destroy], enabled: [Getter/Setter], inspectOpts: {} }, trace: [Function: debug] { namespace: 'helia:trustless-gateway-block-broker:127.0.0.1:trace', useColors: true, color: 129, extend: [Function: extend], destroy: [Function: destroy], enabled: [Getter/Setter], inspectOpts: {} }, diff: 0, prev: undefined, curr: 1744836310513 }, transformRequestInit: undefined }, evicting from session Error: fetching raw block for CID bafkreig7p6kzwgg4hp3n7wpnnn3kkjmpzxds5rmwhphyueilbzabvyexvq from gateway http://127.0.0.1:55970/ was aborted
    at TrustlessGateway.getRawBlock (file:///Users/sgtpooki/code/work/ipshipyard/ipfs/helia/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts:146:15)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at TrustlessGatewaySession.queryProvider (file:///Users/sgtpooki/code/work/ipshipyard/ipfs/helia/packages/block-brokers/src/trustless-gateway/session.ts:38:19)
    at raceSignal (file:///Users/sgtpooki/code/work/ipshipyard/ipfs/helia/node_modules/race-signal/src/index.ts:54:12)
    at Job.run (file:///Users/sgtpooki/code/work/ipshipyard/ipfs/helia/node_modules/@libp2p/utils/src/queue/job.ts:77:22) +0ms
    1) should end session when signal is aborted

Explanation in the code:

  1. provider is evicted when signal is aborted:
    queue.addEventListener('failure', (evt) => {
    this.log.error('error querying provider %o, evicting from session', evt.detail.job.options.provider, evt.detail.error)
    this.evict(evt.detail.job.options.provider)
    })
  2. idle event is fired, but we exit the idle handler:
    if (foundBlock || options.signal?.aborted === true) {
    // we either found the block or the user gave up
    return
    }
  3. nothing else happens.

Metadata

Metadata

Assignees

Labels

P0Critical: Tackled by core team ASAPdif/mediumPrior experience is likely helpfuleffort/hoursEstimated to take one or several hourskind/bugA bug in existing code (including security flaws)need/maintainers-inputNeeds input from the current maintainer(s)status/in-progressIn progress

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions