When I am importing more than 300 record in firebase using google cloud function than am getting error :
Error: function crashed out of request scope Function killed.
Function execution took 31903 ms, finished with status: 'connection error'
Without a glimpse into your code, I only can guess. "Function crashed outside of request scope" indicates that the cloud function had finished before the asynchronous function(s) did. See for documentation for handling async functions and promises:
https://firebase.google.com/docs/functions/terminate-functions
Take a closer look at your returns. Make sure you don't forget to return the promise to functions. For an example see also here: https://github.com/firebase/firebase-functions/issues/18#issuecomment-288375709
I had the same problem and it ended up being a problem with the mysql connection I was using in the project.
In this case I used https://www.npmjs.com/package/mysql2 and the system was losing connections to the database.
It was not clear where it was happening and I got the following errors and no indication where the problem was occurring.
- Error: function crashed out of request scope Function killed.
- Function execution took 31903 ms, finished with status: 'connection error'
Placing try..catch around the database calls revealed the correct error and location where it was happening.
Yout might have gone passed a limit, please look at https://firebase.google.com/docs/database/usage/limits.
If this is the case, you could use multiple databases.
Related
In a NodeJS 6.10.2/SailsJS 0.12.13 based JavaScript application I experience since several months a strange error behavior.
In a Sails controller, I try to retrieve a property of a literal object:
console.log(someObject.someProperty);
console.log("I am still here!");
However, in my case someObject is undefined. So, I'd expect to get an error like 'Cannot read property someProperty of undefined.' - and then either Node.js to stop completely or the code to go on (with the next console.log).
Instead, the code simply stops executing at that point and I get a strange warning: "(node:4822) Warning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit." It is however, unpredictable how often this error occurs. Somethings only once, somethings about 20 times right after each other.
What I found out so for is that it is somehow connected to the question whether there was already a response or not. Consider the following:
mySailsControllerFunction: function(req, res) {
console.log(someObject.someProperty);
console.log("I am still here!");
res.json({"foo":"dahoo"});
}
This will result in Sending 500 ("Server Error") response: ReferenceError: someObject is not defined - exactly what I expect.
However, now I first send some response and then trying to access my non existing property, turning the code into:
mySailsControllerFunction: function(req, res) {
res.json({"foo":"dahoo"});
setTimeout(function () {
console.log("Yeah!");
console.log(someObject.someProperty);
console.log("I am still here!");
},1000);
}
then I often get simply nothing: 'Yeah!' displayed, but nothing comes afterwards. The event listener error is sometimes there, sometimes not. Very strange.
Additionally, and strange enough, the problem seems to be somehow connected to the time passed since the start of Sails. I put the code you see above inside a Sails controller function which is called immediately after the clients re-connect. I then played around with the timeout values, restarting the Sails server several times. Outcome: If I set the timeout to 1s, in 4 of 5 tests, I will get the correct error behavior. For 10 seconds it is about 50%, for 30s the error will always be ignored without any console output.
However, if I put my test code outside of the Sails controller, I always get the correct error behavior by Node. So, I'm quite sure this is a wrong behavior of Sails, not Node.
Disclaimer: I don't know Sails. So it may or may not be related, but my answer may offer a clue.
From the Sails documentation:
http://sailsjs.com/documentation/reference/response-res/res-json
This method is terminal, meaning it is generally the last line of code
your app should run for a given request (hence the advisory usage of
return throughout these docs).
Thus, when you use res.json({"foo":"dahoo"});, Sails probably sends the response back to the client, closing the call sequence, which, if it uses Promises or some other async mechanism, may kind of "swallow" further code, as also suggested in an above comment. This is probably internal coding in Sails, so it's not immediately obvious from the outside WHY your second code block specifically doesn't work.
So you should stick to the first pattern: access your property first, and put res.json() at the end of the controller function.
For reference: I finally solved that issue.
There were, somehow hidden in the code, process exit handlers defined:
process.on('exit', myErrorFunction.bind());
process.on('SIGINT', myErrorFunction.bind());
process.on('uncaughtException', myErrorFunction.bind());
The problem was: The function in which these lines were in was bound to a cronjob. So, each time the cronjob executed, new handlers were registered. So, my assumption above (before vs. after response) was wrong: In fact everything worked till the cronjob was executed for the first time. From then on, it didn't. And eventually, the warning was fired (correctly!).
I would have never found out without this answer: Make node show stack trace after EventEmitter warning
You have to add one line of code to get the stack trace:
process.on('warning', e => console.warn(e.stack));
Additionally, speaking of stack traces: In the Sails serverError response (api/api/responses/serverError.js), it is convenient to access it like this:
module.exports = function serverError (data, options) {
console.log(data.stack);
/* ... */
};
I just saw this error for one of the executions of a cloud function
Function killed. Error: function crashed out of request scope
There are no other supporting logs with more information on the Firebase logs console and I couldn't find more information about this error on the web. I have already discussed the funtion for which I received this error in detail in this question. I have a couple of questions
What does this error mean? Is there a way to get more information for this error. I tried looking for logs in the Google Cloud console for this function but didn't find anything extra.
Is there a way to set alerts when such errors or a timeout occurs for an execution of a function?
When I look at the details of this function on Google Cloud console, it still says that no errors are reported for this function for the last 7 days. The above error has occurred at least once for this function and this function has also timed out a few times in the last 7 days. Are such events not considered as error events for a function?
I have a Parse Cloud Code written in JavaScript, I have an code-based system so I have 3 different modes:
Code is found and have't been used before - SUCCESS
Code is found and have been used before - ERROR
Code isn't found - ERROR
Now, when the client (iOS) gets the success - everything works fine and the code is OK. But I want to determinate between the 2 errors I have and tell the user what's wrong (your code isn't available anymore/code not found), but the error code Parse sends is always 141, so I don't know which message should I print to the user.
How can I change the error code of the error/another way to detect what error is it on client/server side?
Thank you!
From https://parseplatform.github.io/docs/js/guide/#error-codes:
ScriptFailed 141 Cloud Code script failed. Usually points to a JavaScript error. Check error message for more details.
FunctionNotFound 141 Cloud function not found. Check that the specified Cloud function is present in your Cloud Code script and has been deployed.
JobNotFound 141 Background job not found. Check that the specified job is present in your Cloud Code script and has been deployed.
SuccessErrorNotCalled 141 success/error was not called. A cloud function will return once response.success() or response.error() is called. A background job will similarly finish execution once status.success() or status.error() is called. If a function or job never reaches either of the success/error methods, this error will be returned. This may happen when a function does not handle an error response correctly, preventing code execution from reaching the success() method call.
MultupleSuccessErrorCalls 141 Can’t call success/error multiple times. A cloud function will return once response.success() or response.error() is called. A background job will similarly finish execution once status.success() or status.error() is called. If a function or job calls success() and/or error() more than once in a single execution path, this error will be returned.
So looking above, you could have a Javascript error occurring during the function's run. You could be spelling the function name wrong when calling. You could forget to call response.success() to properly close the function. Or you could be calling response.success() / response.error() too many times, make sure that as you follow your code's logic, you only hit one of these for every path.
If you could post the code for your Cloud Code, we might be able to further help you.
I'll describe the problem best as I can - if I've left out details, please tell me - I'm still learning about Protractor.
I'm writing my first protractor test for a website, and its contents are really simple.
teacher.js
describe("teacher list", function () {
beforeEach(function () {
browser.get('http://127.0.0.1:9000/teachers');
});
it("has teacher", function () {
initiateDebug();
var teachers = element.all(by.repeater("teacher in items track by $index"));
initiateDebug();
expect(teachers.count()).toBe(20);
initiateDebug();
})
});
...where initiateDebug() is a function defined in the onPrepare function in protractor_conf.js as follows:
initiateDebug()
global.initiateDebug = function() {
browser.pause(debugPortNumber);
debugPortNumber++;
};
The reason I included this was because calling browser.pause() results in the error:
Port 5858 is already in use. Please specify another port to debug.
[launcher] Process exited with error code 1
and I copied a temp fix proposed by a member in this issue's thread: https://github.com/angular/protractor/issues/2206.
Back to the problem
Question 1
If I run this code, the page just hangs there, and nothing loads. Googling came up with this (Getting error: Error while waiting for Protractor to sync with the page: {}), and I directly used browser.driver.get() and that seems like a workable solution.
However, my first question is - is this a case of it not being able to find angular? Because I distinctly remember that when I ran Protractor a week before, if it couldn't find Angular, it throws this error:
UnknownError: javascript error: angular is not defined
The error from my console, however, is this:
1) teacher list has teacher
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at [object Object]._onTimeout (/Users/Baggio/project/project_bugs/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1812:23)
Question: Is the fact that this error is thrown because the page is forever stuck loading, and the async call never runs? Or could it be that angular doesn't load? Or is it something else?
I'm quite sure protractor loads because I outputted it in the console, it it enumerates all of the object properties.
And as an extension of question 1, here's the next question I don't understand.
Question 2
If I try running this test with browser.driver.get(), I get the exact same error message:
1) teacher list has teacher
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at [object Object]._onTimeout (/Users/Baggio/project/project_bugs/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1812:23)
So it shouldn't have anything to do with the page loading or not.
What I tried
I tried, after calling initiateDebug() in interactive debug mode (entering the exact same line proceeding the first breakpoint, and I got this:
wd-debug> repl
> element.all(by.repeater("teacher in items track by $index"))
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
If I read this correct (https://github.com/angular/protractor/blob/master/docs/debugging.md), entering a protractor command should yield something, but here, it just resumed the control flow outside debug mode, failing the Jasmine spec.
I'll present the relevant code here that:
The html the element.all line is supposed to grab from
<section ng-if="staFlag" class="teacher-item yes-cursor cursor-over" ng-repeat="teacher in items track by $index">
Question 2: Why does Protractor fail here?
Question 3
What I've tried as well - thinking that this is a case where Protractor might not be able to find Angular, defining the rootElement property in protractor_conf.js, (adding ng-app='kp' in the root html file, and rootElement: 'html' in the config file) but it returns yet the exact same error message:
1) teacher list has teacher
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at [object Object]._onTimeout (/Users/Baggio/project/project_bugs/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1812:23)
Message:
Thought 3: Can this effectively prove that this isn't a problem where Protractor can't find Angualr?
Additional information
I have to run this test on the same server where the website is running locally, because for some reason if this starts on a different server, the website doesn't work at all. By "doesn't work", I mean: the page loads correctly, but all bits that require data to be fetched from the backend via Restangular don't show.
Short version question
What exactly is preventing this Protractor test from running correctly? I think I'm missing something very obvious - but I've been looking at this for hours and I haven't come up with any ideas.
I'd really appreciate pointers to the right direction, or a solution if possible - thank you very much.
I have written a cloud function that is working well.
Sometimes this function is being executed more than one time for the same user (I made sure that only one request is being requested from the client android app).
After some debugging I noticed that this problem happens if the connection is bad. I may be or may not be correct.
How to overcome such an issue?
As in the comments I also don't believe the client SDKs would duplicate a Cloud Function call on a bad connection. The expected behaviour would be for them to throw a network-related exception on the client side and not call it again. A problem would arise if the Cloud Function runs successfully and the client is only unable to get the result back.
I can think of the following solutions, with no more details about the Cloud Function itself:
Try to make the function idempotent - Meaning that even if it runs twice the end result is the same, assuming the same input/parameters.
Cache the results and manually throttle the function - This is more complicated, and is only needed if the network problem persists and you can't work around eliminating the side effects of the function. You would have to create another Class to cache the results of the function (maybe keyed by the parameters) and returning the same result with no computation and side effects.