91
91
updateProtocol struct {
92
92
protoInstanceID string
93
93
clientIdentity string
94
+ initialRequest * updatepb.Request
94
95
requestMsgID string
95
96
requestSeqID int64
96
97
scheduleUpdate func (name string , id string , args * commonpb.Payloads , header * commonpb.Header , callbacks UpdateCallbacks )
@@ -134,15 +135,16 @@ func (up *updateProtocol) requireState(action string, valid ...updateState) {
134
135
}
135
136
136
137
func (up * updateProtocol ) HandleMessage (msg * protocolpb.Message ) error {
137
- var req updatepb.Request
138
- if err := msg .Body .UnmarshalTo (& req ); err != nil {
138
+ var request updatepb.Request
139
+ if err := msg .Body .UnmarshalTo (& request ); err != nil {
139
140
return err
140
141
}
142
+ up .initialRequest = & request
141
143
up .requireState ("update request" , updateStateNew )
142
144
up .requestMsgID = msg .GetId ()
143
145
up .requestSeqID = msg .GetEventId ()
144
- input := req .GetInput ()
145
- up .scheduleUpdate (input .GetName (), req .GetMeta ().GetUpdateId (), input .GetArgs (), input .GetHeader (), up )
146
+ input := up . initialRequest .GetInput ()
147
+ up .scheduleUpdate (input .GetName (), up . initialRequest .GetMeta ().GetUpdateId (), input .GetArgs (), input .GetHeader (), up )
146
148
up .state = updateStateRequestInitiated
147
149
return nil
148
150
}
@@ -157,8 +159,11 @@ func (up *updateProtocol) Accept() {
157
159
Body : protocol .MustMarshalAny (& updatepb.Acceptance {
158
160
AcceptedRequestMessageId : up .requestMsgID ,
159
161
AcceptedRequestSequencingEventId : up .requestSeqID ,
162
+ AcceptedRequest : up .initialRequest ,
160
163
}),
161
164
}, withExpectedEventPredicate (up .checkAcceptedEvent ))
165
+ // Stop holding a reference to the initial request to allow it to be GCed
166
+ up .initialRequest = nil
162
167
up .state = updateStateAccepted
163
168
}
164
169
@@ -171,8 +176,8 @@ func (up *updateProtocol) Reject(err error) {
171
176
Body : protocol .MustMarshalAny (& updatepb.Rejection {
172
177
RejectedRequestMessageId : up .requestMsgID ,
173
178
RejectedRequestSequencingEventId : up .requestSeqID ,
179
+ RejectedRequest : up .initialRequest ,
174
180
Failure : up .env .GetFailureConverter ().ErrorToFailure (err ),
175
- // RejectedRequest field no longer read by server - will be removed from API soon
176
181
}),
177
182
})
178
183
up .state = updateStateCompleted
0 commit comments