Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 68087678 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #1142 Avoid possible memory leak with HEAD cache

parent 8d51bc3c
......@@ -116,8 +116,8 @@ export class WS2PCluster {
// More recent?
if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) {
// Check that issuer is a member and that the block exists
const memberKey = await this.isMemberKey(pub)
if (memberKey) {
const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub))
if (isAllowed) {
const exists = await this.existsBlock(blockstamp)
if (exists) {
this.headsCache[fullId] = { blockstamp, message, sig }
......@@ -152,8 +152,8 @@ export class WS2PCluster {
// More recent?
if (!this.headsCache[fullId] || parseInt(this.headsCache[fullId].blockstamp) < parseInt(blockstamp)) {
// Check that issuer is a member and that the block exists
const memberKey = await this.isMemberKey(pub)
if (memberKey) {
const isAllowed = pub === this.server.conf.pair.pub || this.isConnectedKey(pub) || (await this.isMemberKey(pub))
if (isAllowed) {
const exists = await this.existsBlock(blockstamp)
if (exists) {
this.headsCache[fullId] = { blockstamp, message, sig }
......@@ -195,11 +195,17 @@ export class WS2PCluster {
// Do we have this block in the DB?
isMember = !!(await this.server.dal.isMember(pub))
}
// Update the last time it was checked
this.memberkeysCache[pub] = Date.now()
if (isMember) {
// Update the last time it was checked
this.memberkeysCache[pub] = Date.now()
}
return isMember
}
private isConnectedKey(pub:string) {
return this.getConnectedPubkeys().indexOf(pub) !== -1
}
private async existsBlock(blockstamp:string) {
let exists = false
if (this.blockstampsCache[blockstamp]) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment