Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close or Kill a realm sync process for a synced realm #6006

Closed
gauravbordoloi opened this issue Jul 23, 2023 · 23 comments
Closed

Close or Kill a realm sync process for a synced realm #6006

gauravbordoloi opened this issue Jul 23, 2023 · 23 comments

Comments

@gauravbordoloi
Copy link

gauravbordoloi commented Jul 23, 2023

How frequently does the bug occur?

Always

Description

Realm process does not exit when I am closing realm only in case of synced realm. My main issue is I am using Synced Realm with Electron and when I close the electron application, it keeps running in background (doesn't get killed, the synced realm process keeps running)

I tried opening a non synced realm and the process was exiting gracefully.

Is there a way to kill the realm sync process?

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

11.10.1

What services are you using?

Both Atlas Device Sync and Atlas App Services

Are you using encryption?

Yes

Platform OS and version(s)

Node 18.x.x

Build environment

No response

Cocoapods version

No response

@takameyer
Copy link
Contributor

@gauravbordoloi Thanks for submitting this issue. Are you closing the realm when the app is closed?

@gauravbordoloi
Copy link
Author

@takameyer yes i am closing the instances.
In fact the exact code works fine with non synced realm whereas the synced realm is only creating this issue

@gauravbordoloi
Copy link
Author

@takameyer Maybe this is fixed in 12.0.0-rc01 as mentioned in release docs.
Can you please confirm?

image

@takameyer
Copy link
Contributor

@gauravbordoloi It's possible, but I can't confirm 100% of this solves the issue or not. You can try using the current Release Candidate with npm install realm@next. At the moment, it is very stable, so any feedback would be great.

@gauravbordoloi
Copy link
Author

gauravbordoloi commented Jul 27, 2023

Hi @takameyer
I tried using the current release candidate but I am facing the below issue. Do you have a quick fix for this?

Error: Cannot find module '../generated/ts/realm.node'
Require stack:
- A:\homedrop-pos\node_modules\realm\dist\bundle.node.js
- A:\homedrop-pos\node_modules\realm\index.node.js
- A:\homedrop-pos\out\main\index.js
- A:\homedrop-pos\node_modules\electron\dist\resources\default_app.asar\main.js
-
    at Module._resolveFilename (node:internal/modules/cjs/loader:1082:15)
    at n._resolveFilename (node:electron/js2c/browser_init:2:117469)
    at Module._load (node:internal/modules/cjs/loader:927:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1148:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (A:\homedrop-pos\node_modules\realm\dist\bundle.node.js:110:22)
    at Module._compile (node:internal/modules/cjs/loader:1269:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1324:10)
    at Module.load (node:internal/modules/cjs/loader:1124:32)

Current Info -

  1. Windows 11
  2. Node v18.4.0

@takameyer
Copy link
Contributor

@gauravbordoloi Haven't experienced this issue yet. It could be Windows related, but at the moment those tests are passing. Does node_modules\realm\generated\ts\realm.node exist on your system? Perhaps there is some path resolution not happening correctly.

@takameyer
Copy link
Contributor

If you were to modify node_modules\realm\dist\bundle.node.js line 110 to:

const nativeModule = nodeRequire("..\generated\ts\realm.node");

it might work. We might need to sanitise this through path module here.

@gauravbordoloi
Copy link
Author

Hi @takameyer
When I am installing 11.10.1 it is generating realm.node
But when I am installing 12.0.0-rc2 it's not installing as present in screenshot

image

@gauravbordoloi
Copy link
Author

It doesn't even have the generated folder
@takameyer

@takameyer
Copy link
Contributor

@gauravbordoloi Good hint. This should be generated during the npm install process, as the contents of it contain the built realm binary, which we host as a separate download to reduce the size of the package as we need a different binary per architecture. I'll dig into this, perhaps the last release was missing an artifact for windows. Explains why I didn't see this in my environment.

@gauravbordoloi
Copy link
Author

Thanks @takameyer .
Any hack for now to run the current candidate? This problem is creating headache for me. Either I completely move my realm's code to a child process and kill the process or I will use the current candidate with a hackish solution if available.

@takameyer
Copy link
Contributor

Appears something went wrong in our automation:
image

I'll see if I can get the correct binary

@gauravbordoloi
Copy link
Author

Thanks. @takameyer

@takameyer
Copy link
Contributor

@gauravbordoloi Looking into the logs, it appears both win32 and win64 were outputting to the same path. It's possible the contents of this tgz will work if you put it in the node_modules\realm\ folder.
realm-v12.0.0-rc.2-napi-v6-win32-%PREBUILD_ARCH%.tar.gz

I'll keep looking into what the original issue is as this is a blocker for our next release.

@gauravbordoloi
Copy link
Author

Thanks @takameyer , putting the file worked.
Will verify my real problem with this build and post here.

@takameyer
Copy link
Contributor

takameyer commented Jul 27, 2023

Just an update, I was able to figure out our issues with publishing windows binaries. I know that wasn't your original issue, but I still want to thank you for trying this out and making this known.
#6010

@takameyer
Copy link
Contributor

New binaries are now uploaded, so it should work now without manually adding the binary to node_modules. I have verified this in a windows VM.

@gauravbordoloi
Copy link
Author

Thanks a lot @takameyer
Also my core problem is resolved in the 12 version :)

By the way the new release candidate is logging every minute internal details including ssh keys for sync probably, etc.
Is this meant for the RC candidate or there is a way to disable the logging. If I run the production electron app with --trace-warnings these logs become visible, so need to disable this before releasing to prod.
I have attached a screenshot.

Thanks a lot again for the help.

image

@takameyer
Copy link
Contributor

@gauravbordoloi This version introduces more granular logging and we implemented a default logger that should only be logging warnings and errors. Somehow, in your case, it doesn't seem to be functioning as anticipated. You can, however, use the following methods to modify the logger and its threshold:

Realm.setLogger((logLevel, message) => console.log(`${logLevel}:${message}`));
Realm.setLogLevel("debug");

@gauravbordoloi
Copy link
Author

gauravbordoloi commented Jul 28, 2023

Hi @takameyer
✔️ The realm binary is working fine.
❌ The log configuration is not working for setLogLevel. I tried setting off, error, etc but logs are always being shown. However setLogger is working, so I am using Realm.setLogger((logLevel, message) => { }) as a hackish way to solve this

@takameyer
Copy link
Contributor

@gauravbordoloi Strange, I have tried this in a Windows environment using node and I haven't seen any output until I set the proper logLevel. Is it possible you are calling setLogLevel somewhere else in your code?

@gauravbordoloi
Copy link
Author

gauravbordoloi commented Jul 28, 2023

@takameyer
Sorry, mistake from my end. I left out the deprecated log code Realm.App.Sync.setLogLevel(app, "debug") somewhere in my app.
Removed and everything is working perfect now.

You can close this issue. Thanks again :)

@takameyer
Copy link
Contributor

takameyer commented Jul 28, 2023

@gauravbordoloi Happy we got that all worked out! Thanks again for your patience with the new release candidate. Solving that issue saved many others from a giant headache 🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants