推送通知会在Google云端函数中返回ECONNRESET

我在Firebase Cloud Functions中具有检索用户的设备组ID的function,以发送推送通知,并在发送推送通知之后进行。 如果这个函数只被调用一次,这个效果很好,但是如果我有一个用户数组,我也想发送一个推送通知,sendPushNotification函数返回错误: FAILED err= { RequestError: Error: read ECONNRESET at new RequestError (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:14:15)每次尝试发送推送

从我所了解的ECONNRESET意味着连接在完成操作之前一端被closures了,可以有一些帮助/解释我为什么这样做:

这里是我的代码:

 function sendFollowNotification(snapshot) { const notificationMsg = getFollowNotificationMsg() //returns a string snapshot.forEach(function(singleUser, index) { const userId = singleUser.key; const userObject = singleUser.val(); console.log("will get device group") if (index + 1 == snapshot.numChildren()) { return getDeviceGroupNotificationKey(userId, "Discover new artists", notificationMsg, "", true); } else { getDeviceGroupNotificationKey(userId, "Discover new artists", notificationMsg, "", false); } } function getDeviceGroupNotificationKey(groupId, notificationTitle, notificationBody, notificationSubject, shouldReturn) { const pathToDeviceGroup = admin.database().ref('deviceGroups').child(groupId); pathToDeviceGroup.once("value").then( function(snapshot) { const deviceGroupObj = snapshot.val(); const notification_key = deviceGroupObj.notification_key; console.log("got notification key") console.log(notification_key) if (notification_key !== undefined) { return sendPushToDeviceGroupOld(notification_key, notificationTitle, notificationBody, "notificationKeyOld2", notificationSubject, shouldReturn); } else { return } }).catch(reason => { console.log("user device group not there") return }) } function sendPushToDeviceGroupOld(notification_key, title, body, subject, message, shouldReturn) { console.log('sending push to ' + notification_key) const serverKey = '-'; const senderId = '-'; const options = { method: 'POST', uri: 'https://fcm.googleapis.com/fcm/send', headers: { 'Authorization': 'key=' + serverKey, 'project_id': senderId }, body: { to: notification_key, data: { subject: message }, notification: { title: title, body: body, badge: 1, sound: "default", }, priority : 'high', content_available: true }, json: true }; return rqstProm(options) .then((parsedBody) => { console.log('SUCCESS response=', parsedBody); return }) .catch((err) => { console.log('FAILED', err); return }); }