Skip to content

Commit

Permalink
FIX #644 broadcast-channel writes after db.destroy() was called
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed May 16, 2018
1 parent e04f87d commit 5fd6e29
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### X.X.X (comming soon)

Bugfixes:
- Unhandled promise rejection with DOMException [#644](https://github.com/pubkey/rxdb/issues/644)

### 7.6.0 (May 12, 2018)

Bugfixes:
Expand Down
9 changes: 9 additions & 0 deletions src/rx-broadcast-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RxBroadcastChannel {
this.name = name;
this.database = database;
this.token = database.token;
this._destroyed = false;
}

/**
Expand Down Expand Up @@ -53,6 +54,7 @@ class RxBroadcastChannel {
* @return {Promise<any>}
*/
write(type, data) {
if (this._destroyed) return;
return this.bc.postMessage(
JSON.stringify({
type,
Expand All @@ -61,9 +63,16 @@ class RxBroadcastChannel {
t: new Date().getTime()
})
);
/*.catch(err => {
console.error('RxDB: Could not write to BroadcastChannel, this is a bug, report it');
console.dir('type: ' + type);
console.dir('data: ' + data);
console.dir(err);
});*/
}

destroy() {
this._destroyed = true;
this._bc && this._bc.close();
}
}
Expand Down
16 changes: 15 additions & 1 deletion test/unit/rx-broadcast-channel.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import assert from 'assert';

import * as RxDB from '../../dist/lib/index';
import RxDB from '../../dist/lib/index';
import * as util from '../../dist/lib/util';
import AsyncTestUtil from 'async-test-util';
import * as RxBroadcastChannel from '../../dist/lib/rx-broadcast-channel';
import * as humansCollection from '../helper/humans-collection';
import * as schemaObjects from '../helper/schema-objects';

describe('rx-broadcast-channel.test.js', () => {
if (!RxBroadcastChannel.canIUse()) return;
Expand Down Expand Up @@ -86,4 +88,16 @@ describe('rx-broadcast-channel.test.js', () => {
state.otherDB.destroy();
assert.equal(RxDB.dbCount(), 0);
});
describe('ISSUES', () => {
it('#644 Unhandled promise rejection with DOMException', async () => {
await Promise.all(
new Array(10).fill().map(async () => {
const c = await humansCollection.create();
const docData = schemaObjects.human();
await c.insert(docData);
c.database.destroy();
})
);
});
});
});

0 comments on commit 5fd6e29

Please sign in to comment.