Skip to content

Commit 3b10d80

Browse files
committed
tmp: avoid dead lock in callback
1 parent 22f5324 commit 3b10d80

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

c_src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,22 @@ erlfdb_future_cb(FDBFuture* fdb_future, void* data)
7979
// submitted to the network thread or not so that
8080
// we pass the correct environment to enif_send
8181
if(enif_thread_type() == ERL_NIF_THR_UNDEFINED) {
82+
enif_mutex_lock(future->lock);
8283
caller = NULL;
8384
} else {
8485
caller = future->pid_env;
8586
}
8687

87-
enif_mutex_lock(future->lock);
88+
8889

8990
if(!future->cancelled) {
9091
msg = T2(future->msg_env, future->msg_ref, ATOM_ready);
9192
enif_send(caller, &(future->pid), future->msg_env, msg);
9293
}
9394

94-
enif_mutex_unlock(future->lock);
95+
if (!caller) {
96+
enif_mutex_unlock(future->lock);
97+
}
9598

9699
// We're now done with this future which means we need
97100
// to release our handle to it. See erlfdb_create_future

0 commit comments

Comments
 (0)