feat(core): record runtime status while waiting to sign in
Refresh the bundled runtime binaries.
This commit is contained in:
9 files changed
+30
-7
No files matched your search
@@ -103,6 +103,7 @@ export class HookSession extends EventEmitter {
|
|||||||
private disposed = false;
|
private disposed = false;
|
||||||
private loginProbeTimer: ReturnType<typeof setInterval> | null = null;
|
private loginProbeTimer: ReturnType<typeof setInterval> | null = null;
|
||||||
private probing = false;
|
private probing = false;
|
||||||
|
private lastProbeFailure = '';
|
||||||
private acceptedLoginHintUin = '';
|
private acceptedLoginHintUin = '';
|
||||||
private loginHintAttemptUin = '';
|
private loginHintAttemptUin = '';
|
||||||
private loginHintAttempts = 0;
|
private loginHintAttempts = 0;
|
||||||
@@ -670,6 +671,7 @@ export class HookSession extends EventEmitter {
|
|||||||
|
|
||||||
private startLoginReconcile(): void {
|
private startLoginReconcile(): void {
|
||||||
if (this.loginProbeTimer || this.disposed) return;
|
if (this.loginProbeTimer || this.disposed) return;
|
||||||
|
this.log.info('awaiting login: PID=%d', this.pid);
|
||||||
void this.probeLoginOnce(); // immediate — catch already-logged-in fast
|
void this.probeLoginOnce(); // immediate — catch already-logged-in fast
|
||||||
this.loginProbeTimer = setInterval(() => void this.probeLoginOnce(), LOGIN_RECONCILE_INTERVAL_MS);
|
this.loginProbeTimer = setInterval(() => void this.probeLoginOnce(), LOGIN_RECONCILE_INTERVAL_MS);
|
||||||
this.loginProbeTimer.unref?.();
|
this.loginProbeTimer.unref?.();
|
||||||
@@ -694,11 +696,12 @@ export class HookSession extends EventEmitter {
|
|||||||
try {
|
try {
|
||||||
info = await this.probeLogin(this.pid);
|
info = await this.probeLogin(this.pid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.log.trace(
|
const message = errMsg(error);
|
||||||
'login identity probe failed: PID=%d err=%s',
|
const note = `${this.pid}:${message}`;
|
||||||
this.pid,
|
if (this.lastProbeFailure !== note) {
|
||||||
errMsg(error),
|
this.lastProbeFailure = note;
|
||||||
);
|
this.log.warn('login probe failed: PID=%d err=%s', this.pid, message);
|
||||||
|
}
|
||||||
return; // best-effort; the interval retries
|
return; // best-effort; the interval retries
|
||||||
}
|
}
|
||||||
// The await yielded — re-check we still want this before mutating state.
|
// The await yielded — re-check we still want this before mutating state.
|
||||||
@@ -764,6 +767,7 @@ export class HookSession extends EventEmitter {
|
|||||||
this.loginHintAttempts = 0;
|
this.loginHintAttempts = 0;
|
||||||
this.nextLoginHintAt = 0;
|
this.nextLoginHintAt = 0;
|
||||||
this.nextLoginIdentityObservationAt = 0;
|
this.nextLoginIdentityObservationAt = 0;
|
||||||
|
this.lastProbeFailure = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
private handlePacket(packet: QqHookPacket): void {
|
private handlePacket(packet: QqHookPacket): void {
|
||||||
|
|||||||
@@ -6,6 +6,15 @@ import { promisify } from 'util';
|
|||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
const log = createLogger('LoginProbe');
|
const log = createLogger('LoginProbe');
|
||||||
|
const probeNotes = new Map<number, string>();
|
||||||
|
|
||||||
|
function noteProbe(pid: number, result: string, ports: number, processes: number | null): void {
|
||||||
|
const processText = processes === null ? '' : ` processes=${processes}`;
|
||||||
|
const message = `login probe: PID=${pid} result=${result} ports=${ports}${processText}`;
|
||||||
|
if (probeNotes.get(pid) === message) return;
|
||||||
|
probeNotes.set(pid, message);
|
||||||
|
log.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
const CONNECTION_TIMEOUT_MS = 500;
|
const CONNECTION_TIMEOUT_MS = 500;
|
||||||
const COMMAND_TIMEOUT_MS = 1500;
|
const COMMAND_TIMEOUT_MS = 1500;
|
||||||
@@ -164,13 +173,18 @@ async function getProcessPorts(pid: number): Promise<number[] | null> {
|
|||||||
|
|
||||||
async function probeQqLoginInfoInternal(pid: number): Promise<QqPortLoginInfo | null> {
|
async function probeQqLoginInfoInternal(pid: number): Promise<QqPortLoginInfo | null> {
|
||||||
const ports = await getProcessPorts(pid);
|
const ports = await getProcessPorts(pid);
|
||||||
if (ports === null) return null;
|
if (ports === null) {
|
||||||
|
noteProbe(pid, 'unavailable', 0, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (ports.length === 0) {
|
if (ports.length === 0) {
|
||||||
const totalPids = await getQqProcessCount();
|
const totalPids = await getQqProcessCount();
|
||||||
if (totalPids < LOGGED_OUT_PROCESS_COUNT_MAX) {
|
if (totalPids < LOGGED_OUT_PROCESS_COUNT_MAX) {
|
||||||
|
noteProbe(pid, 'no-ports', 0, totalPids);
|
||||||
return { port: 0, uin: '', identityKnown: false };
|
return { port: 0, uin: '', identityKnown: false };
|
||||||
}
|
}
|
||||||
|
noteProbe(pid, 'inconclusive', 0, totalPids);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const ODD_PT_PORTS = [4301, 4303, 4305, 4307, 4309];
|
const ODD_PT_PORTS = [4301, 4303, 4305, 4307, 4309];
|
||||||
@@ -196,16 +210,20 @@ async function probeQqLoginInfoInternal(pid: number): Promise<QqPortLoginInfo |
|
|||||||
} else {
|
} else {
|
||||||
const totalPids = await getQqProcessCount();
|
const totalPids = await getQqProcessCount();
|
||||||
if (totalPids < LOGGED_OUT_PROCESS_COUNT_MAX) {
|
if (totalPids < LOGGED_OUT_PROCESS_COUNT_MAX) {
|
||||||
|
noteProbe(pid, 'no-ports', ports.length, totalPids);
|
||||||
return {
|
return {
|
||||||
port: ports[0] || 0,
|
port: ports[0] || 0,
|
||||||
uin: '',
|
uin: '',
|
||||||
identityKnown: false,
|
identityKnown: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
noteProbe(pid, 'inconclusive', ports.length, totalPids);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background discovery must remain passive. Interactive application
|
// Background discovery must remain passive. Interactive application
|
||||||
// endpoints are deliberately excluded from automatic probing.
|
// endpoints are deliberately excluded from automatic probing.
|
||||||
|
noteProbe(pid, 'no-match', ptPortsToTry.length, null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -676,7 +676,8 @@ describe('probeQqLoginInfo — overall deadline', () => {
|
|||||||
uin: '',
|
uin: '',
|
||||||
identityKnown: false,
|
identityKnown: false,
|
||||||
});
|
});
|
||||||
expect(warnings).toEqual([]);
|
await probeQqLoginInfo(9002);
|
||||||
|
expect(warnings).toEqual(['login probe: PID=9002 result=no-ports ports=0 processes=2']);
|
||||||
} finally {
|
} finally {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
setLogLevel(previousLevel);
|
setLogLevel(previousLevel);
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user