Skip to content

Commit a634264

Browse files
committed
RDBC-694 Fix second leak - calling __exit__ multiple times on the same DocumentStore object causes leaks
1 parent 9e0b10d commit a634264

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

ravendb/documents/identity/hilo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def __init__(self, conventions: "DocumentConventions", generate_id: Callable[[An
1818
self.__conventions = conventions
1919
self.__generate_id = generate_id
2020

21-
def try_get_id_from_instance(self, entity: object) -> Tuple[bool, Union[str, None]]:
21+
def try_get_id_from_instance(self, entity: Union[object, dict]) -> Tuple[bool, Union[str, None]]:
2222
if not entity:
2323
raise ValueError("Entity cannot be None")
2424
identity_property = "Id" # todo: make sure it's ok, create get_identity_property within conventions if not
25-
value = entity.__dict__.get(identity_property, None)
25+
value = (entity if isinstance(entity, dict) else entity.__dict__).get(identity_property, None)
2626
if isinstance(value, str):
2727
return True, value
2828
return False, None

ravendb/documents/store/definition.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ def remove_before_close(self, event: Callable[[], None]):
364364
self.__before_close.remove(event)
365365

366366
def close(self):
367+
if self._disposed:
368+
return
367369
for event in self.__before_close:
368370
event()
369371

@@ -377,8 +379,10 @@ def close(self):
377379
self.__multi_db_hilo.return_unused_range()
378380
except Exception:
379381
pass # ignore
380-
# todo: clear subscriptions
381-
self._disposed = True
382+
383+
if self.subscriptions is not None:
384+
self.subscriptions.close()
385+
382386
for event in self.__after_close:
383387
event()
384388

@@ -389,6 +393,7 @@ def close(self):
389393
lazy.value.close()
390394

391395
self.__thread_pool_executor.shutdown()
396+
self._disposed = True
392397

393398
def open_session(
394399
self, database: Optional[str] = None, session_options: Optional[SessionOptions] = None

ravendb/serverwide/operations/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ def __init__(
222222
)
223223

224224
def get_command(self, conventions: "DocumentConventions") -> RavenCommand[DeleteDatabaseResult]:
225-
return self.__DeleteDatabaseCommand(conventions, self.__parameters)
225+
return self._DeleteDatabaseCommand(conventions, self.__parameters)
226226

227-
class __DeleteDatabaseCommand(RavenCommand[DeleteDatabaseResult], RaftCommand):
227+
class _DeleteDatabaseCommand(RavenCommand[DeleteDatabaseResult], RaftCommand):
228228
def __init__(self, conventions: DocumentConventions, parameters: DeleteDatabaseOperation.Parameters):
229229
super().__init__(DeleteDatabaseResult)
230230

0 commit comments

Comments
 (0)