fix(hook): refresh pipe snapshot before verifying unload took
After native unload returns, the verification check
if (pipeWatcher.isPipeLive(pid)) { ... unload-failed message ... }
read PipeWatcher's cached snapshot, which is updated every 1500ms.
On Windows clicking "Unload" in WebUI almost always tripped this:
the native unload succeeded and the kernel pipe object was gone, but
the watcher's cached "live" state from the previous tick was still
fresh, so the session reported "DLL卸载失败:命名管道仍然存在" even
though the DLL was successfully unloaded. The user then sees the
status flip back to connecting and waits for a real (cached) refresh.
PipeWatcher already exposes tickNow() for exactly this situation —
the load path doesn't need it because injection's verification runs
async via onPipeUp, but unload verifies inline.
HookSessionDeps.pipeWatcher gains an optional `tickNow` and
unloadInternal awaits it before reading isPipeLive. Existing test
mocks that pass only `{ isPipeLive }` keep working (optional chain
is a no-op there). New regression test covers the production
scenario — stale-true cache flipped to false by tickNow.
This commit is contained in:
2 files changed
+40
-3
No files matched your search
@@ -14,8 +14,13 @@ export type HookSessionDeps = {
|
||||
};
|
||||
makeClient: (pid: number) => QqHookClient;
|
||||
/** Sync fast-path check used by load() to skip re-injection when a
|
||||
* prior SnowLuma run left a working pipe behind. */
|
||||
pipeWatcher: { isPipeLive: (pid: number) => boolean };
|
||||
* prior SnowLuma run left a working pipe behind. `tickNow` forces a
|
||||
* fresh poll — used after unload to dodge the up-to-1500ms cache
|
||||
* staleness that would otherwise false-flag a successful unload. */
|
||||
pipeWatcher: {
|
||||
isPipeLive: (pid: number) => boolean;
|
||||
tickNow?: () => Promise<void>;
|
||||
};
|
||||
/** Sink for parsed packets. Called with the BridgeManager-shaped
|
||||
* PacketInfo for every packet received while logged in. If omitted,
|
||||
* packets are dropped (useful in unit tests that don't care). */
|
||||
@@ -254,7 +259,11 @@ export class HookSession extends EventEmitter {
|
||||
this._uin = '0';
|
||||
|
||||
// Verify the unload took: if the pipe is still up the DLL is still
|
||||
// resident. Drop back to 'connecting' and let the watcher reconnect.
|
||||
// resident. The cached snapshot is up to 1500ms stale and we just
|
||||
// changed the world, so force a fresh poll first — otherwise even
|
||||
// a successful unload reads as "pipe still live" until the next
|
||||
// background tick runs and we'd report a spurious failure.
|
||||
await this.pipeWatcher.tickNow?.();
|
||||
if (this.pipeWatcher.isPipeLive(this.pid)) {
|
||||
this._error = 'DLL卸载失败:命名管道仍然存在,watcher将自动重连';
|
||||
this.setStatus('connecting', this._error);
|
||||
|
||||
Reference in new issue
Block a user