closes #7167
[arvados.git] / sdk / go / keepclient / support.go
index 8be178036ad0cce1a447391cf0d3a4ec8e8a625d..0791d3cf856ee7d5d1268338eafa883fe9bcbb18 100644 (file)
@@ -94,8 +94,8 @@ func (this *KeepClient) DiscoverKeepServers() error {
        return this.loadKeepServers(list)
 }
 
-// DiscoverKeepServersFromJSON gets list of available keep services from given JSON
-func (this *KeepClient) DiscoverKeepServersFromJSON(services string) error {
+// LoadKeepServicesFromJSON gets list of available keep services from given JSON
+func (this *KeepClient) LoadKeepServicesFromJSON(services string) error {
        var list svcList
 
        // Load keep services from given json
@@ -248,7 +248,17 @@ func (this KeepClient) putReplicas(
 
        // Used to communicate status from the upload goroutines
        upload_status := make(chan uploadStatus)
-       defer close(upload_status)
+       defer func() {
+               // Wait for any abandoned uploads (e.g., we started
+               // two uploads and the first replied with replicas=2)
+               // to finish before closing the status channel.
+               go func() {
+                       for active > 0 {
+                               <-upload_status
+                       }
+                       close(upload_status)
+               }()
+       }()
 
        // Desired number of replicas
        remaining_replicas := this.Want_replicas