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

fix: free msg_env unconditionally #22

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

savonarola
Copy link
Collaborator

No description provided.

@@ -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);
Copy link
Collaborator Author

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.

@savonarola savonarola marked this pull request as ready for review April 12, 2024 07:01
@savonarola savonarola requested review from qzhuyan and lafirest April 12, 2024 07:16
@@ -86,23 +86,16 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data)
cancelled = future->cancelled;
enif_mutex_unlock(future->cancel_lock);
Copy link

@qzhuyan qzhuyan Apr 12, 2024

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?

Copy link
Collaborator Author

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

Copy link

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?

Copy link

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.

Copy link
Collaborator Author

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

@savonarola savonarola merged commit ee88501 into emqx:dev Apr 12, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants