Skip to content

Commit b773532

Browse files
committed
[push] Waiting for connect promise to resolve
1 parent d04e198 commit b773532

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugins/push/api/jobs/util/connector.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Connector extends DoFinish {
2121
this.db = db;
2222
this.state = state;
2323
this.limit = state.cfg.pool.pushes;
24+
this.connects = [];
2425
this.resetErrors();
2526
}
2627

@@ -182,21 +183,24 @@ class Connector extends DoFinish {
182183
}
183184
else { // no connection yet
184185
this.log.i('Connecting %s', pid);
185-
pools.connect(push.a, push.p, push.f, creds, this.state, this.state.cfg).then(valid => {
186+
let connect = pools.connect(push.a, push.p, push.f, creds, this.state, this.state.cfg).then(valid => {
186187
if (valid) {
187188
this.log.i('Connected %s', pid);
188189
}
189190
else {
190191
app.creds[push.p] = null;
191192
}
193+
this.connects = this.connects.filter(c => c !== connect);
192194
callback(null, push);
193195
}, err => {
194196
this.log.i('Failed to connect %s', pid, err);
195197
app.creds[push.p] = null;
198+
this.connects = this.connects.filter(c => c !== connect);
196199
this.do_transform(push, encoding, callback);
197200
// this.discardedByAppOrCreds.push(push._id);
198201
// this.do_flush(callback, true);
199202
});
203+
this.connects.push(connect);
200204
}
201205
}
202206
}
@@ -392,7 +396,7 @@ class Connector extends DoFinish {
392396
* @param {function} callback callback function
393397
*/
394398
do_final(callback) {
395-
callback();
399+
Promise.all(this.connects).then(() => callback(), () => callback());
396400
}
397401

398402

0 commit comments

Comments
 (0)