Merge PR #1421 from wali-reheman: close previous SessionDB before replacing on cached agent
This commit is contained in:
commit
f05893215e
1 changed files with 9 additions and 0 deletions
|
|
@ -1883,6 +1883,15 @@ def _run_agent_streaming(
|
|||
if hasattr(agent, 'clarify_callback'):
|
||||
agent.clarify_callback = _agent_kwargs.get('clarify_callback')
|
||||
if _session_db is not None:
|
||||
# Close any previously held SessionDB connection before
|
||||
# replacing it. Without this, each streaming request creates
|
||||
# a new SessionDB whose WAL handles leak indefinitely,
|
||||
# eventually causing EMFILE crashes (#streaming FD leak).
|
||||
if hasattr(agent, '_session_db') and agent._session_db is not None:
|
||||
try:
|
||||
agent._session_db.close()
|
||||
except Exception:
|
||||
pass
|
||||
agent._session_db = _session_db
|
||||
if hasattr(agent, '_api_call_count'):
|
||||
agent._api_call_count = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue