Don't leak sendIndexes on disconnect (fixes #2589)

Adds a Closed() method on protocol.Connection and clears up
wireformatConnection a little too.
This commit is contained in:
Jakob Borg
2016-01-11 16:49:44 +01:00
parent 01c70caa8f
commit acdddc0b79
5 changed files with 32 additions and 30 deletions

View File

@@ -1073,10 +1073,18 @@ func sendIndexes(conn protocol.Connection, folder string, fs *db.FileSet, ignore
minLocalVer, err := sendIndexTo(true, 0, conn, folder, fs, ignores)
sub := events.Default.Subscribe(events.LocalIndexUpdated)
// Subscribe to LocalIndexUpdated (we have new information to send) and
// DeviceDisconnected (it might be us who disconnected, so we should
// exit).
sub := events.Default.Subscribe(events.LocalIndexUpdated | events.DeviceDisconnected)
defer events.Default.Unsubscribe(sub)
for err == nil {
if conn.Closed() {
// Our work is done.
return
}
// While we have sent a localVersion at least equal to the one
// currently in the database, wait for the local index to update. The
// local index may update for other folders than the one we are