-
Notifications
You must be signed in to change notification settings - Fork 2
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
Website hangs when trying to connect to an offline relay #2
Comments
I ran a test. Using the below sample code, the following behavior is observed. In the one on top, there is no connection to kitchen, and events work just fine! However on the bottom when trying to connect to kitchen, it hangs, and eventually spits out an error message. This behavior is only observed when using the Can't fetch when one relay is offline: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nostr Event Viewer</title>
</head>
<body>
<h1>Nostr Event Viewer</h1>
<div id="events"></div>
<script type="module">
import NDK from 'https://esm.sh/@nostr-dev-kit/[email protected]';
const nostr = new NDK({
explicitRelayUrls: [
"wss://relay.nostr.band",
"wss://relay.chakany.systems"
],
});
(async () => {
try {
await nostr.connect();
console.log("connected");
const events = nostr.fetchEvents({ kinds: [1] });
events.then((fetchedEvents) => {
fetchedEvents.forEach((event) => {
const eventDiv = document.createElement('div');
eventDiv.textContent = event.content;
document.getElementById('events').appendChild(eventDiv);
});
});
} catch (error) {
console.error(error);
}
})();
</script>
</body>
</html> Can fetch when one relay is offline: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nostr Event Viewer</title>
</head>
<body>
<h1>Nostr Event Viewer</h1>
<div id="events"></div>
<script type="module">
import NDK from 'https://esm.sh/@nostr-dev-kit/[email protected]';
const nostr = new NDK({
explicitRelayUrls: [
"wss://relay.nostr.band",
"wss://kitchen.zap.cooking"
],
});
(async () => {
try {
await nostr.connect();
console.log("connected");
const sub = nostr.subscribe({ kinds: [1] });
sub.on("event", (event) => {
const eventDiv = document.createElement('div');
eventDiv.textContent = event.content;
document.getElementById('events').appendChild(eventDiv);
});
} catch (error) {
console.error(error);
}
})();
</script>
</body>
</html> |
opened a bug report in ndk under nostr-dev-kit/ndk#306 |
Incident
I attempted to mitigate slowdowns caused by connecting to multiple relays simultaneously and fetching all their events by making the kitchen relay the default relay. However, when the
kitchen.zap.cooking
relay went down, the website stopped functioning. I promptly added another default relay, b6031c7, but it was ineffective. While the profiles loaded and you could view those recipes, nothing on the recents page or any of the categories loaded, but the profiles did. Notably, if I removed the offline relay, the website would suddenly start working again.Initial Assumptions
My initial assumption is that there is a bug in the NDK that is causing this issue. I will open an issue to report it.
Mitigation
For now, I have implemented a temporary fix by filtering out the
kitchen.zap.cooking
relay from the relay list on load in the commit 710dab3.The text was updated successfully, but these errors were encountered: