-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: free msg_env unconditionally #22
Conversation
@@ -86,23 +86,16 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data) | |||
cancelled = future->cancelled; | |||
enif_mutex_unlock(future->cancel_lock); | |||
|
|||
enif_mutex_lock(future->msg_lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock seems useless—it saves only from concurrent erlfdb_future_cb
invocations, which the fdb driver should prevent.
But if it somehow happens, then we will anyway run into problems calling enif_release_resource(future)
twice.
@@ -86,23 +86,16 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data) | |||
cancelled = future->cancelled; | |||
enif_mutex_unlock(future->cancel_lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid question, do we released the lock too early?
image two processes are cancelling the future if it can happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fdb allows double cancelling; it only forbids double destroy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If FDB ensures the callback is executed exact once as the cancel could be triggered by FDB or by NIF.
and the deref of future NIF resource is only done (for NIF part) in the callback https://github.com/emqx/couchdb-erlfdb/pull/22/files#diff-ceadfa165520612e5b6b1a255f7680bcaa9e2a67bf47677f6884fd1db3cb03f5L110 .
Then I think the future->cancel_lock is not needed at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is unrelated to this PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
future->cancelled
is independently set from two different nifs; so, formally, we need synchronization
No description provided.