Skip to content

Commit 53c6a7e

Browse files
author
lambda-tooling+rie
committed
Update from upstream - 2026-07-24
1 parent 3656a0d commit 53c6a7e

18 files changed

Lines changed: 152 additions & 16 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ tags
77
.idea
88
.DS_Store
99
.venv
10+
build.log

internal/lambda-managed-instances/aws-lambda-rie/internal/invoke/rie_invoke_request.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type rieInvokeRequest struct {
4040
cognitoIdentityPoolId string
4141
clientContext string
4242
responseMode string
43+
internalInvocationID string
4344

4445
functionVersionID string
4546
}
@@ -98,6 +99,7 @@ func NewRieInvokeRequest(request *http.Request, writer http.ResponseWriter) (*ri
9899
cognitoIdentityPoolId: cognitoIdentityPoolId,
99100
clientContext: clientContext,
100101
responseMode: request.Header.Get(invoke.ResponseModeHeader),
102+
internalInvocationID: uuid.New().String(),
101103
}
102104

103105
return req, nil
@@ -184,3 +186,7 @@ func (r *rieInvokeRequest) UpdateFromInitData(initData interop.InitStaticDataPro
184186
func (r *rieInvokeRequest) FunctionVersionID() string {
185187
return r.functionVersionID
186188
}
189+
190+
func (r *rieInvokeRequest) InternalInvocationID() string {
191+
return r.internalInvocationID
192+
}

internal/lambda-managed-instances/aws-lambda-rie/internal/invoke/rie_invoke_request_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func TestNewRieInvokeRequest(t *testing.T) {
143143
if tt.want.invokeID == "" {
144144
tt.want.invokeID = got.invokeID
145145
}
146+
tt.want.internalInvocationID = got.internalInvocationID
146147

147148
assert.Equal(t, tt.want, got)
148149
})

internal/lambda-managed-instances/interop/mock_invoke_request.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ func (_m *MockInvokeRequest) FunctionVersionID() string {
143143
return r0
144144
}
145145

146+
func (_m *MockInvokeRequest) InternalInvocationID() string {
147+
ret := _m.Called()
148+
149+
if len(ret) == 0 {
150+
panic("no return value specified for InternalInvocationID")
151+
}
152+
153+
var r0 string
154+
if rf, ok := ret.Get(0).(func() string); ok {
155+
r0 = rf()
156+
} else {
157+
r0 = ret.Get(0).(string)
158+
}
159+
160+
return r0
161+
}
162+
146163
func (_m *MockInvokeRequest) InvokeID() string {
147164
ret := _m.Called()
148165

internal/lambda-managed-instances/interop/sandbox_model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ type InvokeRequest interface {
302302

303303
UpdateFromInitData(InitStaticDataProvider) model.AppError
304304
FunctionVersionID() string
305+
306+
InternalInvocationID() string
305307
}
306308

307309
type InitStaticDataProvider interface {

internal/lambda-managed-instances/invoke/consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const (
99
FunctionErrorBodyTrailer = "lambda-runtime-function-error-body"
1010
ResponseModeHeader = "invoke-response-mode"
1111
TraceIdHeader = "x-amzn-trace-id"
12+
13+
RuntimeInvocationIdHeader = "lambda-runtime-invocation-id"
1214
)
1315

1416
type InvokeBodyResponseStatus string

internal/lambda-managed-instances/invoke/invoke_router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type RuntimeResponseRequest interface {
3535
BodyReader() io.Reader
3636

3737
TrailerError() ErrorForInvoker
38+
39+
InvocationID() string
3840
}
3941

4042
type RuntimeErrorRequest interface {
@@ -47,6 +49,8 @@ type RuntimeErrorRequest interface {
4749
ReturnCode() int
4850
ErrorDetails() string
4951
GetXrayErrorCause() json.RawMessage
52+
53+
InvocationID() string
5054
}
5155

5256
type runningInvoke interface {

internal/lambda-managed-instances/invoke/mock_runtime_error_request.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ func (_m *MockRuntimeErrorRequest) ReturnCode() int {
171171
return r0
172172
}
173173

174+
func (_m *MockRuntimeErrorRequest) InvocationID() string {
175+
ret := _m.Called()
176+
177+
if len(ret) == 0 {
178+
panic("no return value specified for InvocationID")
179+
}
180+
181+
var r0 string
182+
if rf, ok := ret.Get(0).(func() string); ok {
183+
r0 = rf()
184+
} else {
185+
r0 = ret.Get(0).(string)
186+
}
187+
188+
return r0
189+
}
190+
174191
func NewMockRuntimeErrorRequest(t interface {
175192
mock.TestingT
176193
Cleanup(func())

internal/lambda-managed-instances/invoke/mock_runtime_response_request.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ func (_m *MockRuntimeResponseRequest) TrailerError() ErrorForInvoker {
122122
return r0
123123
}
124124

125+
func (_m *MockRuntimeResponseRequest) InvocationID() string {
126+
ret := _m.Called()
127+
128+
if len(ret) == 0 {
129+
panic("no return value specified for InvocationID")
130+
}
131+
132+
var r0 string
133+
if rf, ok := ret.Get(0).(func() string); ok {
134+
r0 = rf()
135+
} else {
136+
r0 = ret.Get(0).(string)
137+
}
138+
139+
return r0
140+
}
141+
125142
func NewMockRuntimeResponseRequest(t interface {
126143
mock.TestingT
127144
Cleanup(func())

internal/lambda-managed-instances/invoke/running_invoke.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ type runningInvokeImpl struct {
6868
invokeRespSender InvokeResponseSender
6969
runtimeNext http.ResponseWriter
7070

71+
internalInvocationID string
72+
7173
responderFactoryFunc ResponderFactoryFunc
7274
sendInvokeToRuntime func(context.Context, interop.InitStaticDataProvider, interop.InvokeRequest, http.ResponseWriter, string) (int64, time.Duration, time.Duration, model.AppError)
7375
createTracingData func(traceId string, tracingMode intmodel.XrayTracingMode, segmentIDGenerator func() string) (downstreamTraceId string, tracingCtx *interop.TracingCtx)
@@ -99,6 +101,8 @@ func newRunningInvoke(
99101
func (r *runningInvokeImpl) RunInvokeAndSendResult(ctx context.Context, initData interop.InitStaticDataProvider, invokeReq interop.InvokeRequest, metrics interop.InvokeMetrics) model.AppError {
100102
downstreamTraceId, tracingCtx := r.createTracingData(invokeReq.TraceId(), initData.XRayTracingMode(), xray.GenerateSegmentID)
101103

104+
r.internalInvocationID = invokeReq.InternalInvocationID()
105+
102106
metrics.TriggerStartRequest()
103107
if err := metrics.SendInvokeStartEvent(tracingCtx); err != nil {
104108
logging.Error(ctx, "Failed to send InvokeStartEvent", "err", err)
@@ -290,11 +294,28 @@ func (r *runningInvokeImpl) RuntimeResponse(ctx context.Context, runtimeRespReq
290294
return model.NewCustomerError(model.ErrorRuntimeInvokeResponseInProgress)
291295
}
292296

297+
if echoedID := runtimeRespReq.InvocationID(); echoedID != "" && r.internalInvocationID != "" {
298+
if echoedID != r.internalInvocationID {
299+
logging.Warn(ctx, "Cross-wiring detected: invocation ID mismatch on response",
300+
"expected", r.internalInvocationID, "received", echoedID)
301+
r.responseState.CompareAndSwap(stateGotResponse, stateNoResponse)
302+
return model.NewCustomerError(model.ErrorRuntimeInvokeTimeout)
303+
}
304+
}
305+
293306
r.runtimeResponseChan <- runtimeRespReq
294307
return <-r.responseSentChan
295308
}
296309

297310
func (r *runningInvokeImpl) RuntimeError(ctx context.Context, runtimeErrReq RuntimeErrorRequest) model.AppError {
311+
if echoedID := runtimeErrReq.InvocationID(); echoedID != "" && r.internalInvocationID != "" {
312+
if echoedID != r.internalInvocationID {
313+
logging.Warn(ctx, "Cross-wiring detected: invocation ID mismatch on error",
314+
"expected", r.internalInvocationID, "received", echoedID)
315+
return model.NewCustomerError(model.ErrorRuntimeInvokeTimeout)
316+
}
317+
}
318+
298319
oldState := r.responseState.Swap(stateGotError)
299320
if oldState == stateGotError {
300321
logging.Warn(ctx, "Invalid invoke state : error in progress")

0 commit comments

Comments
 (0)