mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 08:21:20 +00:00
Disconnect stale connections, see if this helps with stalling stuff
This commit is contained in:
parent
95ccc51a44
commit
f526ec5c58
@ -1,5 +1,5 @@
|
||||
import {partition} from "ramda"
|
||||
import {noop} from "hurdak"
|
||||
import {max, partition} from "ramda"
|
||||
import {noop, pickVals} from "hurdak"
|
||||
import {Plex, Relays, Executor, Multi} from "paravel"
|
||||
import {error, warn} from "src/util/logger"
|
||||
import {normalizeRelayUrl} from "src/engine/relays/utils"
|
||||
@ -82,3 +82,17 @@ export const getExecutor = (urls: string[]) => {
|
||||
|
||||
return executor
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
const activityKeys = ["lastRequest", "lastPublish", "lastEvent"]
|
||||
|
||||
for (const [url, con] of pool.data.entries()) {
|
||||
// @ts-ignore
|
||||
const lastActivity = pickVals(activityKeys, con.meta).reduce(max)
|
||||
|
||||
// If our connection hasn't been used in a while, close it and reopen
|
||||
if (lastActivity && lastActivity < Date.now() - 60_000) {
|
||||
pool.remove(url)
|
||||
}
|
||||
}
|
||||
}, 10_000)
|
||||
|
@ -43,9 +43,15 @@ export class Subscription extends EventEmitter {
|
||||
setTimeout(this.close, timeout)
|
||||
}
|
||||
|
||||
const urls = getUrls(relays)
|
||||
this.executor = getExecutor(getUrls(relays))
|
||||
|
||||
// If one of our connections gets closed make sure to kill our sub
|
||||
this.executor.target.connections.forEach(con => {
|
||||
con.on("close", () => {
|
||||
this.close()
|
||||
})
|
||||
})
|
||||
|
||||
this.executor = getExecutor(urls)
|
||||
this.sub = this.executor.subscribe(filters, {
|
||||
onEvent: this.onEvent,
|
||||
onEose: this.onEose,
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
const setDate = d => {
|
||||
date = d
|
||||
console.log(d)
|
||||
value = formatDateAsLocalISODate(d).slice(0, 10)
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ const WARN_TAGS = new Set([
|
||||
"porn",
|
||||
"ass",
|
||||
"boob",
|
||||
"boostr",
|
||||
"boobstr",
|
||||
"sex",
|
||||
"sexy",
|
||||
"fuck",
|
||||
|
Loading…
Reference in New Issue
Block a user