Skip to content

Commit fc4092e

Browse files
joe4devclaude
andcommitted
refactor(init): construct the LocalStack adapter inside the interop server
The adapter was hoisted into main.go "so it can be shared with the interop server", but nothing in main.go uses it after the constructor call — main reaches the adapter through interopServer.localStackAdapter. Revert to in-constructor creation and drop the extra parameter. Also fix a stale comment in events.go referencing a CustomInteropServer.onDemand field that does not exist. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a6c21d0 commit fc4092e

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

cmd/localstack/custom_interop.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,16 @@ func (l *LocalStackAdapter) SendResult(invokeId string, body []byte, isError boo
9999
return l.post(endpoint, body)
100100
}
101101

102-
func NewCustomInteropServer(lsOpts *LsOpts, adapter *LocalStackAdapter, delegate interop.Server, logCollector *LogCollector, eventsAPI *LocalStackEventsAPI) (server *CustomInteropServer) {
102+
func NewCustomInteropServer(lsOpts *LsOpts, delegate interop.Server, logCollector *LogCollector, eventsAPI *LocalStackEventsAPI) (server *CustomInteropServer) {
103103
server = &CustomInteropServer{
104-
delegate: delegate.(*rapidcore.Server),
105-
port: lsOpts.InteropPort,
106-
upstreamEndpoint: lsOpts.RuntimeEndpoint,
107-
localStackAdapter: adapter,
108-
eventsAPI: eventsAPI,
104+
delegate: delegate.(*rapidcore.Server),
105+
port: lsOpts.InteropPort,
106+
upstreamEndpoint: lsOpts.RuntimeEndpoint,
107+
localStackAdapter: &LocalStackAdapter{
108+
UpstreamEndpoint: lsOpts.RuntimeEndpoint,
109+
RuntimeId: lsOpts.RuntimeId,
110+
},
111+
eventsAPI: eventsAPI,
109112
}
110113

111114
// TODO: extract this

cmd/localstack/events.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ type LocalStackEventsAPI struct {
3636
// never calls — i.e. unbounded memory growth in warm environments.
3737
lambdatelemetry.NoOpEventsAPI
3838
logCollector *LogCollector
39-
// onDemand mirrors CustomInteropServer.onDemand: only on-demand functions report the
40-
// cold-start init duration in their first invocation's REPORT line (AWS omits it for
41-
// provisioned-concurrency and Managed Instances invokes).
39+
// onDemand is true for on-demand functions (see the onDemand classification in main.go):
40+
// only those report the cold-start init duration in their first invocation's REPORT line
41+
// (AWS omits it for provisioned-concurrency and Managed Instances invokes).
4242
onDemand bool
4343

4444
mu sync.Mutex

cmd/localstack/main.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,6 @@ func main() {
195195
localStackLogsEgressApi := NewLocalStackLogsEgressAPI(logCollector)
196196
tracer := NewLocalStackTracer()
197197

198-
// Create LocalStack adapter upfront so it can be shared with the interop server
199-
lsAdapter := &LocalStackAdapter{
200-
UpstreamEndpoint: lsOpts.RuntimeEndpoint,
201-
RuntimeId: lsOpts.RuntimeId,
202-
}
203-
204198
// onDemand is true for on-demand functions, where AWS folds a failed cold-start init into
205199
// the first invocation (suppressed init). For these we do NOT report init failures via
206200
// /status/error; instead we signal ready and let the first invoke surface the error with
@@ -250,7 +244,7 @@ func main() {
250244
runDaemon(d) // async
251245

252246
defaultInterop := sandbox.DefaultInteropServer()
253-
interopServer := NewCustomInteropServer(lsOpts, lsAdapter, defaultInterop, logCollector, lsEventsAPI)
247+
interopServer := NewCustomInteropServer(lsOpts, defaultInterop, logCollector, lsEventsAPI)
254248
sandbox.SetInteropServer(interopServer)
255249
if len(handler) > 0 {
256250
sandbox.SetHandler(handler)

0 commit comments

Comments
 (0)