firebase / firebase/geofire-js

Maximum call stack size exceeded error

Open
#267 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.4k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

I have node js server with express framework with latest version when My server try to running this code parallel this gives me error like this
```
node_modules/geofire/dist/geofire/index.cjs.js:8458
if (other === this) {
^

RangeError: Maximum call stack size exceeded
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8458:9)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
at ChildrenNode.equals (node_modules/geofire/dist/geofire/index.cjs.js:8466:37)
```

Here is the my code example

```
function getNearBy(
center,
maxRadius,
stepRadius = 0.5,
startRadius = 0
) {
var tableRef = firebaseTable.ref("table1");
var findRef = firebaseTable.ref("table2");
return new Promise((resolve, reject) => {
try {
const queryResults = [],
geoQuery = findRef.query({
center,
radius: Math.min(maxRadius, startRadius || stepRadius)
});
geoQuery.on("key_entered", (key, location, distance) => {
var ref = tableRef.child(key);
ref.once("value").then(function (snapshot) {
if (snapshot.exists()) {
const val = snapshot.val();
queryResults.push(val)
}
});
});
geoQuery.on("ready", () => {
if (queryResults.length > 6) {
geoQuery.cancel(); // unsubscribe all event listeners and destroy query
resolve(queryResults);
return;
}
if (geoQuery.radius() >= maxRadius) {
geoQuery.cancel(); // unsubscribe all event listeners and destroy query
resolve(queryResults);
return;
}
geoQuery.updateCriteria({
radius: Math.min(maxRadius, geoQuery.radius() + stepRadius)
});
});
} catch (error) {
console.log("error", error);
}
});
}
const getNearByIDs = ({ pick_up_latitude, pick_up_longitude, radius }) => {
return new Promise((resolve, reject) => {
async function main() {
try {
const pick_up_geopoint = [
parseFloat(pick_up_latitude),
parseFloat(pick_up_longitude)
];

let id = await getNearBy(
pick_up_geopoint,
radius
);
resolve(id);
return;
} catch (error) {
console.log("error", error);
reject(error);
return;
}
}
main();
});
};
const notify = () => {
return new Promise((resolve, reject) => {
async function main() {
try {
const totalMS = 1000;
let removeDriver = "";
for (let index = 0; index < 5; index++) {
setTimeout(myFunction, i * totalMS);
async function myFunction() {
try {
let ids = await getNearByIDs({
pick_up_latitude: xx,
pick_up_longitude: xx,
radius: xx
});
} catch (error) {
console.log("error", error);
return;
}
}
}
return;
} catch (error) {
console.log("error", error);
reject(error);
return;
}
}
main();
});
};
```
When I try to call notify function parallel more than 2-3 times it is breaking down entire server.
Please help me with this issue

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided parallel notify/getNearBy calls and inspect the ChildrenNode.equals stack trace in node_modules/geofire/dist/geofire/index.cjs.js. Compare behavior with one, two, and several concurrent calls; done means the server no longer overflows the call stack under the reported parallel workload.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, firebase, javascript, node.js, typescript
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.