Firebase child.once在auth.signInWithEmailAndPasswordcallback中超时不一致

我有一个简单的nodejs服务,在AWS EC2(ubuntu)中运行firebase。 我所要做的就是使用Firebase身份validationlogin用户,并在成功login时返回用户信息(附加信息)。

问题是,从用户对象获取用户信息的调用正在超时。 并非所有的时间,这是不一致的,而且总是当我第一次尝试在早上(或几个小时的空闲服务器)。 我从卷发中注意到的,是一天中的第一个要求,花费很长时间才能返回大约30多秒。 (使用免费的Firebase)

你能帮我确定我做错了什么吗? 我该如何解决这个问题?

find下面的代码:

const auth = firebase.auth(); const users = firebase.database().ref('users'); const db = firebase.database(); /* ..a lot of code in between.. */ let login = function(requestParam, callback) { console.log('userhandler.login called ' + new Date() + ' ' + requestParam.email) auth.signInWithEmailAndPassword(requestParam.email, requestParam.password).catch((error)=>{ console.log("error while signInWithEmailAndPassword " + error); console.log(new Date()); }).then((userData) => { console.log('auth.signin .then called ' + new Date()) console.log(userData.uid + ' ' + new Date()); db.ref('/users/' + userData.uid).limitToFirst(1).once("value", (snapshot) => { // users.child(userData.uid).once("value", (snapshot) => { console.log('auth.signin.then.child.once called ' + new Date()) let user = snapshot.val(); callback(null, _.extend(user, {user_id : userData.uid})); }, (error) => { console.log('Error getting user list'); callback(errors.authenticationFailure(error), null); }).catch((error) => { callback(error, null); }); }, (error) => { console.log('Invalid Username or password'); callback(errors.authenticationFailure(error), null); }).catch((error) => { callback(error, null); }); }; 

users.childdb.ref('/users/id')注意到同样的问题。

Nodejs日志如下:

来自我的应用程序的请求(超时在客户端)

 userhandler.login called Sun Oct 08 2017 13:10:05 GMT+0000 (UTC) MYUSERID@EMAIL.com auth.signin .then called Sun Oct 08 2017 13:10:05 GMT+0000 (UTC) rNmrXXXXXXXXXXXXZjuSDn2 Sun Oct 08 2017 13:10:05 GMT+0000 (UTC) POST /api/users/login - - ms - - 

请求curl

 userhandler.login called Sun Oct 08 2017 13:11:57 GMT+0000 (UTC) MYUSERID@EMAIL.com auth.signin .then called Sun Oct 08 2017 13:11:58 GMT+0000 (UTC) rNmrXXXXXXXXXXXXZjuSDn2 Sun Oct 08 2017 13:11:58 GMT+0000 (UTC) auth.signin.then.child.once called Sun Oct 08 2017 13:11:33 GMT+0000 (UTC) POST /api/users/login 200 35319.714 ms - 273 

后续调用来自app还是curl在<500 ms内返回响应:

 userhandler.login called Sun Oct 08 2017 13:13:56 GMT+0000 (UTC) MYUSERID@EMAIL.com auth.signin .then called Sun Oct 08 2017 13:13:57 GMT+0000 (UTC) rNmrXXXXXXXXXXXXZjuSDn2 Sun Oct 08 2017 13:13:57 GMT+0000 (UTC) auth.signin.then.child.once called Sun Oct 08 2017 13:13:57 GMT+0000 (UTC) POST /api/users/login 200 489.888 ms - 273