Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e02d13

Browse files
committed
Merge pull request 'fix: reload config race condition' (#525) from reload-race-condition into main
Reviewed-on:https://git.biggo.com/Funmula/dive-mcp-host/pulls/525
2 parents6a1e951 +8ca278e commit5e02d13

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

‎dive_mcp_host/host/host.py‎

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
)
9494
self._store=store_manager
9595
self._exit_stack:AsyncExitStack|None=None
96+
self._lock:asyncio.Lock=asyncio.Lock()
9697

9798
asyncdef_run_in_context(self)->AsyncGenerator[Self,None]:
9899
asyncwithAsyncExitStack()asstack:
@@ -196,45 +197,48 @@ async def reload(
196197
Chats can be resumed after reload by using the same chat_id.
197198
"""
198199
# NOTE: Do Not restart MCP Servers when there is on-going query.
199-
ifself._exit_stackisNone:
200-
raiseRuntimeError("Host not initialized")
201-
202-
# Update config
203-
old_config=self._config
204-
self._config=new_config
205-
206-
try:
207-
# Reload model if needed
208-
ifold_config.llm!=new_config.llm:
209-
self._model=None
210-
awaitself._init_models()
211-
212-
awaitself._tool_manager.reload(
213-
new_configs=new_config.mcp_servers,force=force_mcp
214-
)
215-
216-
# Reload checkpointer if needed
217-
ifold_config.checkpointer!=new_config.checkpointer:
218-
ifself._checkpointerisnotNone:
219-
awaitself._exit_stack.aclose()
220-
self._checkpointer=None
221-
222-
ifnew_config.checkpointer:
223-
checkpointer=get_checkpointer(str(new_config.checkpointer.uri))
224-
self._checkpointer=awaitself._exit_stack.enter_async_context(
225-
checkpointer
226-
)
227-
awaitself._checkpointer.setup()
228-
229-
# Call the reloader function to handle service restart
230-
ifreloader:
231-
awaitreloader()
232-
233-
exceptExceptionase:
234-
# Restore old config if reload fails
235-
self._config=old_config
236-
logging.error("Failed to reload host: %s",e)
237-
raise
200+
asyncwithself._lock:
201+
ifself._exit_stackisNone:
202+
raiseRuntimeError("Host not initialized")
203+
204+
# Update config
205+
old_config=self._config
206+
self._config=new_config
207+
208+
try:
209+
# Reload model if needed
210+
ifold_config.llm!=new_config.llm:
211+
self._model=None
212+
awaitself._init_models()
213+
214+
awaitself._tool_manager.reload(
215+
new_configs=new_config.mcp_servers,force=force_mcp
216+
)
217+
218+
# Reload checkpointer if needed
219+
ifold_config.checkpointer!=new_config.checkpointer:
220+
ifself._checkpointerisnotNone:
221+
awaitself._exit_stack.aclose()
222+
self._checkpointer=None
223+
224+
ifnew_config.checkpointer:
225+
checkpointer=get_checkpointer(
226+
str(new_config.checkpointer.uri)
227+
)
228+
self._checkpointer=awaitself._exit_stack.enter_async_context(
229+
checkpointer
230+
)
231+
awaitself._checkpointer.setup()
232+
233+
# Call the reloader function to handle service restart
234+
ifreloader:
235+
awaitreloader()
236+
237+
exceptExceptionase:
238+
# Restore old config if reload fails
239+
self._config=old_config
240+
logging.error("Failed to reload host: %s",e)
241+
raise
238242

239243
@property
240244
defconfig(self)->HostConfig:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp