Skip to content

Commit 3bf413f

Browse files
nesitorhoh
authored andcommitted
Fix: Instead using a semaphore, changed to use a lock.
1 parent 46fbf2d commit 3bf413f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/aleph/vm/pool.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
import json
55
import logging
6+
import threading
67
from collections.abc import Iterable
78
from datetime import datetime, timezone
89
from typing import Optional
@@ -43,12 +44,12 @@ class VmPool:
4344
network: Optional[Network]
4445
snapshot_manager: Optional[SnapshotManager] = None
4546
systemd_manager: SystemDManager
46-
creation_semaphore: asyncio.Semaphore
47+
creation_lock: threading.Lock
4748

4849
def __init__(self):
4950
self.counter = settings.START_ID_INDEX
5051
self.executions = {}
51-
self.creation_semaphore = asyncio.Semaphore(1)
52+
self.creation_lock = threading.Lock()
5253

5354
self.network = (
5455
Network(
@@ -89,7 +90,7 @@ async def create_a_vm(
8990
) -> VmExecution:
9091
"""Create a new Aleph Firecracker VM from an Aleph function message."""
9192

92-
await self.creation_semaphore.acquire()
93+
self.creation_lock.acquire()
9394

9495
# Check if an execution is already present for this VM, then return it.
9596
# Do not `await` in this section.
@@ -135,12 +136,10 @@ async def create_a_vm(
135136
self.forget_vm(vm_hash)
136137
raise
137138
finally:
138-
self.creation_semaphore.release()
139+
self.creation_lock.release()
139140

140141
self._schedule_forget_on_stop(execution)
141142

142-
self.creation_semaphore.release()
143-
144143
return execution
145144

146145
def get_unique_vm_id(self) -> int:

0 commit comments

Comments
 (0)