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

Commitf201d1a

Browse files
committed
chore: improve logging for findSSHProcessID
1 parent1e56a3f commitf201d1a

File tree

1 file changed

+77
-23
lines changed

1 file changed

+77
-23
lines changed

‎src/remote.ts‎

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -829,46 +829,100 @@ export class Remote {
829829
// findSSHProcessID returns the currently active SSH process ID that is
830830
// powering the remote SSH connection.
831831
privateasyncfindSSHProcessID(timeout=15000):Promise<number|undefined>{
832+
constlogger=getMemoryLogger()
833+
logger.info(`Starting SSH process ID search with timeout:${timeout}ms`)
834+
835+
letattempts=0
836+
letlastFilePath:string|undefined
837+
832838
constsearch=async(logPath:string):Promise<number|undefined>=>{
833-
// This searches for the socksPort that Remote SSH is connecting to. We do
834-
// this to find the SSH process that is powering this connection. That SSH
835-
// process will be logging network information periodically to a file.
836-
consttext=awaitfs.readFile(logPath,"utf8")
837-
constmatches=text.match(/->socksPort(\d+)->/)
838-
if(!matches){
839-
return
840-
}
841-
if(matches.length<2){
842-
return
843-
}
844-
constport=Number.parseInt(matches[1])
845-
if(!port){
846-
return
847-
}
848-
constprocesses=awaitfind("port",port)
849-
if(processes.length<1){
850-
return
839+
try{
840+
// This searches for the socksPort that Remote SSH is connecting to. We do
841+
// this to find the SSH process that is powering this connection. That SSH
842+
// process will be logging network information periodically to a file.
843+
consttext=awaitfs.readFile(logPath,"utf8")
844+
845+
if(attempts%5===0){
846+
logger.debug(`SSH log file size:${text.length} bytes`)
847+
}
848+
849+
constmatches=text.match(/->socksPort(\d+)->/)
850+
if(!matches){
851+
return
852+
}
853+
if(matches.length<2){
854+
return
855+
}
856+
constport=Number.parseInt(matches[1])
857+
if(!port){
858+
return
859+
}
860+
861+
logger.info(`Found SSH socks port:${port}, searching for process`)
862+
constprocesses=awaitfind("port",port)
863+
864+
if(processes.length<1){
865+
logger.debug(`No processes found using port:${port}`)
866+
return
867+
}
868+
869+
constprocess=processes[0]
870+
logger.info(`Found SSH process: PID=${process.pid}, CMD=${process.cmd}`)
871+
returnprocess.pid
872+
}catch(error){
873+
logger.error(`Error searching for SSH process in log:${logPath}`,error)
874+
returnundefined
851875
}
852-
constprocess=processes[0]
853-
returnprocess.pid
854876
}
877+
855878
conststart=Date.now()
879+
856880
constloop=async():Promise<number|undefined>=>{
857-
if(Date.now()-start>timeout){
881+
attempts++
882+
883+
constelapsed=Date.now()-start
884+
if(elapsed>timeout){
885+
logger.info(`SSH process ID search timed out after${attempts} attempts, elapsed:${elapsed}ms`)
858886
returnundefined
859887
}
888+
889+
// Log progress periodically
890+
if(attempts%5===0){
891+
logger.info(`SSH process ID search attempt #${attempts}, elapsed:${elapsed}ms`)
892+
logger.logMemoryUsage("SSH_PROCESS_SEARCH")
893+
}
894+
860895
// Loop until we find the remote SSH log for this window.
861896
constfilePath=awaitthis.storage.getRemoteSSHLogPath()
897+
862898
if(!filePath){
863-
returnnewPromise((resolve)=>setTimeout(()=>resolve(loop()),500))
899+
if(lastFilePath!==filePath){
900+
lastFilePath=filePath
901+
logger.debug(`SSH log file not found, will retry`)
902+
}
903+
904+
returnnewPromise((resolve)=>{
905+
setTimeout(()=>resolve(loop()),500)
906+
})
907+
}
908+
909+
if(lastFilePath!==filePath){
910+
lastFilePath=filePath
911+
logger.info(`Found SSH log file:${filePath}`)
864912
}
913+
865914
// Then we search the remote SSH log until we find the port.
866915
constresult=awaitsearch(filePath)
867916
if(!result){
868-
returnnewPromise((resolve)=>setTimeout(()=>resolve(loop()),500))
917+
returnnewPromise((resolve)=>{
918+
setTimeout(()=>resolve(loop()),500)
919+
})
869920
}
921+
922+
logger.info(`SSH process ID search completed successfully after${attempts} attempts, elapsed:${elapsed}ms`)
870923
returnresult
871924
}
925+
872926
returnloop()
873927
}
874928

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp