Merge pull request #1725 from realm/kneth/backporting-1724
Avoid leaking realms when an error occurs within an event handler
This commit is contained in:
commit
08dcbf4312
|
@ -43,7 +43,14 @@ process.on('message', (m) => {
|
||||||
if (impl.onchange) {
|
if (impl.onchange) {
|
||||||
const change = Realm.Sync._deserializeChangeSet(m.change);
|
const change = Realm.Sync._deserializeChangeSet(m.change);
|
||||||
if (!change.isEmpty) {
|
if (!change.isEmpty) {
|
||||||
impl.onchange(change);
|
try {
|
||||||
|
impl.onchange(change);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
change.close();
|
||||||
|
process.send({change: m.change});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
change.close();
|
change.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,24 @@ class FunctionListener {
|
||||||
changes.release();
|
changes.release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const promise = Promise.resolve(this.fn(changes));
|
|
||||||
|
let promise;
|
||||||
|
try {
|
||||||
|
promise = Promise.resolve(this.fn(changes));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
changes.release();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
this.pending.push(promise);
|
this.pending.push(promise);
|
||||||
promise.then(() => {
|
const release = () => {
|
||||||
changes.release();
|
changes.release();
|
||||||
this.pending.splice(this.pending.indexOf(promise), 1);
|
this.pending.splice(this.pending.indexOf(promise), 1);
|
||||||
|
};
|
||||||
|
promise.then(release).catch(e => {
|
||||||
|
release();
|
||||||
|
throw e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue