diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c
index a23b31ee2e6971cbe073f1edb6bc663c9c61a0ee..6302ac6555efdae75caa1379693648dd50401b51 100644
--- a/pbx/pbx_lua.c
+++ b/pbx/pbx_lua.c
@@ -982,7 +982,9 @@ static lua_State *lua_get_state(struct ast_channel *chan)
 		}
 		return L;
 	} else {
+		ast_channel_lock(chan);
 		datastore = ast_channel_datastore_find(chan, &lua_datastore, NULL);
+		ast_channel_unlock(chan);
 
 		if (!datastore) {
 			/* nothing found, allocate a new lua state */