I would like to open a change stream to get notified of changes to a collection.
The client receives changes until the change stream is closed.
The change stream times out after a few minutes (according to the Realm logs, the stream stays open for about 90 to 240 seconds) and receives no more change events. The following error message is logged in the browser console.
Uncaught (in promise) WatchError: execution time limit exceeded
WatchError https://unpkg.com/[email protected]/dist/bundle.iife.js:9540
feedSse https://unpkg.com/[email protected]/dist/bundle.iife.js:9686
feedLine https://unpkg.com/[email protected]/dist/bundle.iife.js:9611
advanceBufferState https://unpkg.com/[email protected]/dist/bundle.iife.js:9746
feedBuffer https://unpkg.com/[email protected]/dist/bundle.iife.js:9590
watch https://unpkg.com/[email protected]/dist/bundle.iife.js:9916
async function reproduction() {
const app = new Realm.App("<app id>");
await app.logIn(Realm.Credentials.anonymous());
const collection = app.currentUser
.mongoClient("mongodb-atlas")
.db("<database>")
.collection("<collection>")
for await (const change of collection.watch()) {
console.log(change);
}
}
I believe it is a duplicate of https://github.com/realm/realm-js/issues/3283
@kneth The issues look similar but the WatchError messages are different (execution time limit exceeded in this issue and rule with id="000000000000000000000000" no longer exists on mongodb service, closing watch stream in #3283). According to this comment in the other issue, there is a server-side bug if Sync is enabled but I have Sync disabled in my project and still get the timeout error.
Is there anything I can do to help? I'd be happy to put together a small reproduction repository or Realm project if that helps with debugging.
We're experiencing this exact same issue using the latest version of realm-web. Any fixes coming @kraenhansen ?
@versoworks we're still missing a reproduction case for this.
I retested with an app on CodeSandbox (https://codesandbox.io/s/realm-watch-test-9c8bw) but I cannot reproduce the error above. I would appreciate any steps or details that might help me reproduce this: I.e. browser name, version and MongoDB Realm rules used, would be great.
@kraenhansen Thank you for trying to reproduce the issue! I looked into it a little more and found out what causes the error. The change stream times out if a function is called in an apply_when expression. To reproduce, create a function named testFunction that returns true:
exports = function () {
return true;
};
Then add this apply_when expression for the runs collection:
{
"%%true": {
"%function": {
"name": "testFunction"
}
}
}
I tested it with your CodeSandbox (after replacing realmjstestapp-jjhtf with my own app ID) and the change stream stops with the execution time limit exceeded error after a minute or two.
Can confirm this issue, we have seen this happen as well. I've taken the liberty to write a small app to reproduce the issue over here: https://realm-change-stream-test.netlify.app
edit: to clarify, the Realm app is using a function as part of a rule as described by @klaussner in the above comment
@kraenhansen Now that there is a reproduction case for this, is there any more info?
Would it be practical to try and handle the error in the client and resume watching in the meantime?
@nverba & @rvanmil since the issue is reproduced by changing a server-side configuration this is most likely not an issue with the Realm JS / Web SDKs (and I'll close it as such). That being said, I've relayed this as a question internally and I'll update this issue when I get more information.
You might want to ask on the community forums as well (linking to this issue) if you want to speed things up and get other members of the community a chance to tip in: https://community.mongodb.com/
Most helpful comment
@nverba & @rvanmil since the issue is reproduced by changing a server-side configuration this is most likely not an issue with the Realm JS / Web SDKs (and I'll close it as such). That being said, I've relayed this as a question internally and I'll update this issue when I get more information.
You might want to ask on the community forums as well (linking to this issue) if you want to speed things up and get other members of the community a chance to tip in: https://community.mongodb.com/