mirror of
https://github.com/rclone/rclone.git
synced 2026-10-28 06:18:39 -04:00
sftp: fix data race when using --sftp-ssh
When the sftp backend uses an external ssh program (--sftp-ssh), one goroutine waits for the ssh program to finish by calling cmd.Wait(). cmd.Wait() sets cmd.ProcessState when the program ends. At the same time, CanReuse() calls exited(), which reads cmd.ProcessState without any lock. This is a data race and the Go race detector reports it. It happens in normal use, for example when a connection is put back in the pool after a stat. The race only decides whether a pooled connection can be reused, so it is unlikely to cause problems in practice, but it makes programs that use the sftp backend fail when they are tested with -race. This fix sets an atomic.Bool after cmd.Wait() returns and makes exited() read that instead of cmd.ProcessState. It also adds a test which calls exited() while Wait() is running. It fails with -race before this fix and passes after it.
This commit is contained in:
500 Internal Server Error
Gitea Version: 1.28.0+dev-477-g8b6ad49a5f