-
Notifications
You must be signed in to change notification settings - Fork 20
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
Passing fun()
to ra:*_query()
may break when executed on a remote node
#238
Comments
I'm wondering if the use of an anonymous @ansd, @dcorbacho, @the-mikedavis: Any opinion? |
What are the rare issues that are difficult to debug when always using the |
Khepri uses local queries with the local node only: LocalServerId = {StoreId, node()},
Ret = ra:local_query(LocalServerId, QueryFun, Timeout),
Sorry I was unclear. I prepared a patch so that Khepri always use MFA. We should be fine on this front. However, APIs such as |
[Why] Using `fun()` is fragile if it has to be executed on a remote node. Indeed, the remote node may have another version of the module hosting the function and the function reference may be invalid. [How] Now, we always use an exported function. Callers of any folding APIs should do the same. Fixes #238.
Yes, I think that's a good idea. |
[Why] Using `fun()` is fragile if it has to be executed on a remote node. Indeed, the remote node may have another version of the module hosting the function and the function reference may be invalid. [How] Now, we always use an exported function. Callers of any folding APIs should do the same. Fixes #238.
After putting more thoughts into this, I believe the problem is larger. In fact, there are two problems.
We could add one somewhat related issue: Ra machine versions compatibility. The validity of a function reference on a remote nodeThis the one we attempt to fix here. Indeed, depending on the version of Erlang/OTP or the remote module hosting the function, the reference could be invalid and the Ra machine could crash trying to run it. This can be solved by always using exported functions and MFA as proposed in the current patch. But this brings us to the second problem… The possible difference of code between the local copy and the remote oneIf Khepri or the application using it are updated on one of the Erlang nodes, the code of the query the caller thinks will be executed might be different or even incompatible with the code actually executed on the remote node. This could mean an unexpected result or a crash. Ra machine versions compatibilitySpeaking of upgrades, we have the same king of problem if Khepri’s Ra machine’s state changes. If the query code doesn’t know about the new or old state, again, it can give bad results or crash. That’s why I’m pausing work on this patch and started to discuss solutions with @kjnilsson. |
This is fixed by #260. |
Passing an anonymous function reference for execution on a remote node may break if the remote node has another version of Erlang or the module hosting the anonymous function.
It would be better to call an exported function.
Reporter by: @ansd
The text was updated successfully, but these errors were encountered: