Closed allouis closed 1 week ago
Please let me know the version of Fedify and Node.js you are using.
@dahlia We're using fedify@0.9.1
and node v20.14.0
I think this issue is related: https://github.com/digitalbazaar/jsonld.js/issues/451
Specifically this comment https://github.com/digitalbazaar/jsonld.js/issues/451#issuecomment-997826749
What is the reasoning behind using "manual" mode for redirects? Is that part of the JSON-LD spec for resolving contexts?
This seems to not be an issue with Fedify, this stems from using Docker somehow...
Both of these commands should not error
> node -e "fetch('https://w3id.org/security/v1').then(console.log, console.log)"
> node -e "fetch('https://www.w3.org/ns/activitystreams').then(console.log, console.log)"
But, if I run these commands inside of docker - the first one will error
If I run:
docker run -it node:lts-alpine node -e "fetch('https://w3id.org/security/v1').then(console.log, console.log)"
Then I get:
TypeError: fetch failed
at node:internal/deps/undici/undici:12502:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[cause]: AggregateError [ETIMEDOUT]:
at internalConnectMultiple (node:net:1117:18)
at internalConnectMultiple (node:net:1185:5)
at Timeout.internalConnectMultipleTimeout (node:net:1711:5)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
code: 'ETIMEDOUT',
[errors]: [ [Error], [Error] ]
}
}
This is really weird behaviour and can be replicated by some members of our team, but not all!
Is there an easy way to hardcode the values of this into the cache?
That's indeed very strange!
Is there an easy way to hardcode the values of this into the cache?
The best way would be to implement your own context loader! E.g.,
import { fetchDocumentLoader, RemoteDocument } from "@fedify/fedify";
async function cachedContextLoader(url: string): Promise<RemoteDocument> {
if (url === "https://w3id.org/security/v1") {
return {
contextUrl: null,
documentUrl: url,
document: {
"@context": { ... }
}
};
}
return await fetchDocumentLoader(url);
}
const federation = new Federation<void>({
contextLoader: cachedContextLoader,
});
Hey @dahlia
I've tried your suggestion but I'm still running into issues
Here's what I've tried:
const securityDoc = {
contextUrl: null,
documentUrl: 'https://w3id.org/security/v1',
document: {
"@context": {
...
}
}
};
import { fetchDocumentLoader, RemoteDocument, getAuthenticatedDocumentLoader } from "@fedify/fedify";
async function cachedContextLoader(url: string): Promise<RemoteDocument> {
if (url === "https://w3id.org/security/v1" || url === "https://w3id.org/security/v1/") {
return securityDoc;
}
return await fetchDocumentLoader(url);
}
const fedifyKv = new MemoryKvStore();
fedifyKv.set(['_fedify', 'remoteDocument', 'https://w3id.org/security/v1/'], securityDoc);
fedifyKv.set(['_fedify', 'remoteDocument', 'https://w3id.org/security/v1'], securityDoc);
const fedify = new Federation<ContextData>({
kv: fedifyKv,
contextLoader: cachedContextLoader,
documentLoader: cachedContextLoader,
authenticatedDocumentLoaderFactory: (identity) => {
const loader = getAuthenticatedDocumentLoader(identity);
return async function load(url) {
if (url === "https://w3id.org/security/v1" || url === "https://w3id.org/security/v1/") {
return securityDoc;
}
return await loader(url);
}
},
treatHttps: true
});
And I am getting this error when attempting to send activities to other actors
activitypub-1 | 02:58:52.009 DBG fedify·runtime·docloader Fetching document: 'GET' 'https://w3id.org/security/v1' { accept: 'application/activity+json, application/ld+json' }
activitypub-1 | jsonld.InvalidUrl: Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context.
activitypub-1 | at ContextResolver._fetchContext (/opt/activitypub/node_modules/jsonld/lib/ContextResolver.js:173:13)
activitypub-1 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
activitypub-1 | at async ContextResolver._resolveRemoteContext (/opt/activitypub/node_modules/jsonld/lib/ContextResolver.js:117:34)
activitypub-1 | at async ContextResolver.resolve (/opt/activitypub/node_modules/jsonld/lib/ContextResolver.js:50:22)
activitypub-1 | at async api.process (/opt/activitypub/node_modules/jsonld/lib/context.js:87:20)
activitypub-1 | at async api.expand (/opt/activitypub/node_modules/jsonld/lib/expand.js:214:17)
activitypub-1 | at async jsonld.expand (/opt/activitypub/node_modules/jsonld/lib/jsonld.js:322:18)
activitypub-1 | at async Object.fromJsonLd (file:///opt/activitypub/node_modules/@fedify/fedify/esm/vocab/vocab.js:1993:30)
activitypub-1 | at async lookupObject (file:///opt/activitypub/node_modules/@fedify/fedify/esm/vocab/lookup.js:77:16)
activitypub-1 | at <anonymous> (/opt/activitypub/src/app.ts:302:27) {
activitypub-1 | details: {
activitypub-1 | code: 'loading remote context failed',
activitypub-1 | url: 'https://w3id.org/security/v1',
activitypub-1 | cause: TypeError: fetch failed
activitypub-1 | at node:internal/deps/undici/undici:12502:13
activitypub-1 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
activitypub-1 | at async fetchDocumentLoader (file:///opt/activitypub/node_modules/@fedify/fedify/esm/runtime/docloader.js:70:22)
activitypub-1 | at async ContextResolver._fetchContext (/opt/activitypub/node_modules/jsonld/lib/ContextResolver.js:166:19)
activitypub-1 | at async ContextResolver._resolveRemoteContext (/opt/activitypub/node_modules/jsonld/lib/ContextResolver.js:117:34)
activitypub-1 | at async ContextResolver.resolve (/opt/activitypub/node_modules/jsonld/lib/ContextResolver.js:50:22)
activitypub-1 | at async api.process (/opt/activitypub/node_modules/jsonld/lib/context.js:87:20)
activitypub-1 | at async api.expand (/opt/activitypub/node_modules/jsonld/lib/expand.js:214:17)
activitypub-1 | at async jsonld.expand (/opt/activitypub/node_modules/jsonld/lib/jsonld.js:322:18)
activitypub-1 | at async Object.fromJsonLd (file:///opt/activitypub/node_modules/@fedify/fedify/esm/vocab/vocab.js:1993:30) {
activitypub-1 | [cause]: [AggregateError]
activitypub-1 | }
activitypub-1 | }
activitypub-1 | }
It's as if the context isn't always loaded through the document/context loader and is falling back to the default? Do you know what could be causing this?
Looks like you've used lookupObject()
from your app, right? Could you try to pass your custom context loader to lookupObject()
too? It should work!
@allouis By the way, I filed a new issue you probably will be interested in: https://github.com/dahlia/fedify/issues/74.
@allouis Is your issue now resolved? Would it be okay if I close this issue?
Sorry I missed this - yeah this is resolved now with the hardcoded contexts!
I've configured the
Federation
instance to have an actor and keypair dispatcher like below (Currently I'm returningnull
for debugging purposes, but the error happens when I return a keypair, too)When I try to read the Actor data via curl like:
I get this error:
I then updated to only set an actor dispatcher like so:
And curling this gives the same error!