@@ -15,7 +15,9 @@ limitations under the License.
15
15
package aws
16
16
17
17
import (
18
+ "bytes"
18
19
"context"
20
+ "encoding/json"
19
21
"fmt"
20
22
"sync"
21
23
"time"
@@ -132,8 +134,16 @@ func (b *CreateFleetBatcher) runCalls() {
132
134
// we know that these create fleet calls are identical so we can just run the first one and increase the number
133
135
// of instances that we request
134
136
call := requestBatch [0 ]
135
- call .input .TargetCapacitySpecification .SetTotalTargetCapacity (int64 (len (requestBatch )))
136
- outputs , err := b .ec2api .CreateFleetWithContext (call .ctx , call .input )
137
+ // deep copy the input we are about to modify so that we don't modify any caller's input parameter
138
+ input , err := deepCopy (call .input )
139
+ if err != nil {
140
+ // shouldn't occur, but if it does we log an error and just modify the caller's input so we
141
+ // can continue to launch instances
142
+ logging .FromContext (context .Background ()).Infof ("error copying input, %s" , err )
143
+ input = call .input
144
+ }
145
+ input .TargetCapacitySpecification .SetTotalTargetCapacity (int64 (len (requestBatch )))
146
+ outputs , err := b .ec2api .CreateFleetWithContext (call .ctx , input )
137
147
138
148
// error occurred at the CreateFleet call level, so notify all requestors of the same error
139
149
if err != nil {
@@ -195,3 +205,17 @@ func (b *CreateFleetBatcher) runCalls() {
195
205
}
196
206
}
197
207
}
208
+
209
+ func deepCopy (v * ec2.CreateFleetInput ) (* ec2.CreateFleetInput , error ) {
210
+ var buf bytes.Buffer
211
+ enc := json .NewEncoder (& buf )
212
+ if err := enc .Encode (v ); err != nil {
213
+ return nil , err
214
+ }
215
+ dec := json .NewDecoder (& buf )
216
+ var cp ec2.CreateFleetInput
217
+ if err := dec .Decode (& cp ); err != nil {
218
+ return nil , err
219
+ }
220
+ return & cp , nil
221
+ }
0 commit comments