pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.52k stars 380 forks source link

Client connection recv() waitgroup fix #541

Closed TechieDheeraj closed 1 year ago

TechieDheeraj commented 1 year ago

In GoRoutine Client is calling sftp.clientConn.recv() call at line 242 and Wait group is incremented by one before go routine starts at line 238 but main thread is not waiting for go routine to complete the recv() api call and eventually returning at line 247.

puellanivis commented 1 year ago

The purpose of this WaitGroup is to prevent clientConn.Close() from returning before recv() has completed. The necessary purpose of NewClientPipe is that it has to return while recv is in the background receiving responses as a long-lived background goroutine.

As such, including this code would cause NewClientPipe to never return before the connection itself had been terminated, thus breaking all functionality. Testing locally, this change does indeed lock up go test.

I’m immediately closing this PR as it is entirely unworkable and based on a faulty assumption of code behavior… possibly received from something like ChatGPT?