diff --git a/main/channel.c b/main/channel.c
index 902c79d853e4d0fae962d82b3f7fc0d628510fee..f4a04d52f348b334614ed1780a4a6f3727fed5c7 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -6518,10 +6518,18 @@ int ast_do_masquerade(struct ast_channel *original)
 	 * for deadlock avoidance will not result in any sort of masquerade race condition.
 	 * If masq is called by a different thread while this happens, it will be stuck waiting
 	 * until we unlock the container. */
-	while (ast_channel_trylock(clonechan)) {
+	while ((clonechan = original->masq) && ast_channel_trylock(clonechan)) {
 		CHANNEL_DEADLOCK_AVOIDANCE(original);
 	}
 
+	/* recheck if masq has been done the deadlock avoidance above could cause a double masq
+	 * this is posible with at least ast_hangup*/
+	if (!original->masq) {
+		ast_channel_unlock(original);
+		ao2_unlock(channels);
+		return 0; /* masq already completed by another thread, or never needed to be done to begin with */
+	}
+
 	/* Get any transfer masquerade connected line exchange data. */
 	xfer_ds = ast_channel_datastore_find(original, &xfer_ds_info, NULL);
 	if (xfer_ds) {