Skip to content

Commit 5d6a1b4

Browse files
committed
fix: pin.remote.ls status check
This fixes a racy bug: when a single service was offline, any remaining services were not checked due to error thrown. This usually did not happen in Chromium, but failed pretty often in Firefox, which seem to execute looped for awaits bit differently.
1 parent a19a5ef commit 5d6a1b4

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ yarn-error.log*
2323
.vscode
2424
.idea
2525
.eslintcache
26+
tsconfig.tsbuildinfo

src/bundles/pinning.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const parseService = async (service, availablePinningServices, ipfs) => {
2222
* @property {string} name
2323
* @property {('queued'|'pinning'|'pinned'|'failed')} status
2424
* @property {string} cid
25-
* @property {Array<string>} [delegates] e.g. ["/dnsaddr/pin-service.example.com"]
25+
* @property {Array<string>} [delegates] (multiaddrs endind with /p2p/peerid)
2626
*/
2727
const pinningBundle = {
2828
name: 'pinning',
@@ -57,26 +57,25 @@ const pinningBundle = {
5757

5858
if (!ipfs || store?.ipfs?.ipfs?.ready || !ipfs.pin.remote) return
5959

60-
const pinsGenerator = pinningServices.map(async service => ({
61-
pins: await ipfs.pin.remote.ls({
62-
service: service.name
63-
}),
64-
serviceName: service.name
65-
}))
66-
6760
dispatch({ type: 'SET_REMOTE_PINS', payload: [] })
6861

69-
for await (const { pins, serviceName } of pinsGenerator) {
70-
for await (const pin of pins) {
71-
dispatch({
72-
type: 'ADD_REMOTE_PIN',
73-
payload: {
74-
...pin,
75-
id: `${serviceName}:${pin.cid}`
76-
}
77-
})
62+
await Promise.all(pinningServices.map(async service => {
63+
try {
64+
const pins = ipfs.pin.remote.ls({ service: service.name })
65+
for await (const pin of pins) {
66+
dispatch({
67+
type: 'ADD_REMOTE_PIN',
68+
payload: {
69+
...pin,
70+
id: `${service.name}:${pin.cid}`
71+
}
72+
})
73+
}
74+
} catch (_) {
75+
// if one of services is offline, ignore it for now
76+
// and continue checking remaining ones
7877
}
79-
}
78+
}))
8079
},
8180

8281
selectRemotePins: (state) => state.pinning.remotePins || [],
@@ -101,8 +100,8 @@ const pinningBundle = {
101100
dispatch({ type: 'SET_REMOTE_PINNING_SERVICES_AVAILABLE', payload: true })
102101

103102
const availablePinningServices = store.selectAvailablePinningServices()
104-
const firstListOfServices = await ipfs.pin.remote.service.ls()
105-
const remoteServices = await Promise.all(firstListOfServices.map(service => parseService(service, availablePinningServices, ipfs)))
103+
const offlineListOfServices = await ipfs.pin.remote.service.ls()
104+
const remoteServices = await Promise.all(offlineListOfServices.map(service => parseService(service, availablePinningServices, ipfs)))
106105
dispatch({ type: 'SET_REMOTE_PINNING_SERVICES', payload: remoteServices })
107106

108107
const fullListOfServices = await ipfs.pin.remote.service.ls({ stat: true })

0 commit comments

Comments
 (0)