@@ -27,8 +27,11 @@ type CustomInteropServer struct {
2727 localStackAdapter * LocalStackAdapter
2828 port string
2929 upstreamEndpoint string
30- initStart time.Time
31- warmStart bool
30+ // initStart is set once in Init() and warmStart is flipped on the first invoke.
31+ // Both are accessed only from the single sequential init -> invoke flow (the RIE
32+ // processes one invocation at a time), so they need no additional synchronization.
33+ initStart time.Time
34+ warmStart bool
3235}
3336
3437type LocalStackAdapter struct {
@@ -45,10 +48,11 @@ const (
4548
4649func (l * LocalStackAdapter ) SendStatus (status LocalStackStatus , payload []byte ) error {
4750 statusUrl := fmt .Sprintf ("%s/status/%s/%s" , l .UpstreamEndpoint , l .RuntimeId , status )
48- _ , err := http .Post (statusUrl , "application/json" , bytes .NewReader (payload ))
51+ resp , err := http .Post (statusUrl , "application/json" , bytes .NewReader (payload ))
4952 if err != nil {
5053 return err
5154 }
55+ defer resp .Body .Close ()
5256 return nil
5357}
5458
@@ -58,8 +62,12 @@ func (l *LocalStackAdapter) SendLogs(invokeId string, logs LogResponse) error {
5862 if err != nil {
5963 return err
6064 }
61- _ , err = http .Post (l .UpstreamEndpoint + "/invocations/" + invokeId + "/logs" , "application/json" , bytes .NewReader (serialized ))
62- return err
65+ resp , err := http .Post (l .UpstreamEndpoint + "/invocations/" + invokeId + "/logs" , "application/json" , bytes .NewReader (serialized ))
66+ if err != nil {
67+ return err
68+ }
69+ defer resp .Body .Close ()
70+ return nil
6371}
6472
6573// SendResult posts the invocation result body to LocalStack.
@@ -79,8 +87,12 @@ func (l *LocalStackAdapter) SendResult(invokeId string, body []byte, isError boo
7987 } else {
8088 log .Infoln ("Sending to /response" )
8189 }
82- _ , err := http .Post (l .UpstreamEndpoint + endpoint , "application/json" , bytes .NewReader (body ))
83- return err
90+ resp , err := http .Post (l .UpstreamEndpoint + endpoint , "application/json" , bytes .NewReader (body ))
91+ if err != nil {
92+ return err
93+ }
94+ defer resp .Body .Close ()
95+ return nil
8496}
8597
8698// The InvokeRequest is sent by LocalStack to trigger an invocation
@@ -94,12 +106,12 @@ type InvokeRequest struct {
94106
95107// The ErrorResponse is sent TO LocalStack when encountering an error
96108type ErrorResponse struct {
97- ErrorMessage string `json:"errorMessage"`
98- ErrorType string `json:"errorType,omitempty"`
109+ ErrorMessage string `json:"errorMessage"`
110+ ErrorType string `json:"errorType,omitempty"`
99111 // RequestId uses *string so that an empty string "" is serialized (not omitted),
100112 // while nil is omitted — init errors always set this field, fault events leave it nil.
101- RequestId * string `json:"requestId,omitempty"`
102- StackTrace []string `json:"stackTrace,omitempty"`
113+ RequestId * string `json:"requestId,omitempty"`
114+ StackTrace []string `json:"stackTrace,omitempty"`
103115}
104116
105117func NewCustomInteropServer (lsOpts * LsOpts , adapter * LocalStackAdapter , delegate interop.Server , logCollector * LogCollector ) (server * CustomInteropServer ) {
0 commit comments