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