fix: finish owned idle sessions before proving resource release

This commit was merged in pull request #18.
This commit is contained in:
阿白叔 committed 2026-11-19 11:14:49 +08:00
1 parent 3bde847ff7
commit 55cdf2b082
10 files changed
+632 -8

No files matched your search

+8 -2
View File
@@ -41,6 +41,7 @@ def hold_release_files(library, roots=None, *, timeout_seconds=10, stop=None):
if record.get('token') != token or record.get('status') != 'HELD' or process.poll() is not None:
error = OSError('FILE_PROBE_UNCONFIRMED: '+str(record.get('error', '探测身份或句柄失效')))
error.winerror = record.get('winerror')
error.blocked_resources = record.get('blocked_resources', [])
raise error
# Duplicate the already-open handles before acknowledging the probe.
# Its exit can never create a gap in the parent's commit protection.
@@ -108,6 +109,7 @@ def file_probe_main(job):
job = Path(job)
request = json.loads(job.read_text('utf-8'))
result = {'token': request['token'], 'status': 'UNCONFIRMED'}
opening = None
try:
def checked_path(value):
path = Path(value).absolute()
@@ -127,15 +129,18 @@ def file_probe_main(job):
with ExitStack() as stack:
handles = []
for path in snapshot['exclusive_files']:
opening = path
handle = win32file.CreateFile(path, win32con.GENERIC_READ, 0, None,
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
stack.callback(handle.Close)
handles.append(int(handle))
for path in snapshot['binding_files']:
opening = path
handle = win32file.CreateFile(path, win32con.GENERIC_READ, win32con.FILE_SHARE_READ,
None, win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
stack.callback(handle.Close)
handles.append(int(handle))
opening = None
if _snapshot(library, roots) != snapshot:
raise ValueError('占用检查期间资源集合变化')
pending = job.with_name('result.pending')
@@ -145,7 +150,8 @@ def file_probe_main(job):
return 0
except Exception as error:
pending = job.with_name('result.pending')
pending.write_text(json.dumps({**result, 'error': str(error),
'winerror': getattr(error, 'winerror', None)}), 'utf-8')
blocked = [opening] if opening and getattr(error, 'winerror', None) in (32,33) else []
pending.write_text(json.dumps({**result, 'error': (opening+': ' if opening else '')+str(error),
'winerror': getattr(error, 'winerror', None), 'blocked_resources': blocked}), 'utf-8')
pending.replace(job.with_name('result.json'))
return 1