Skip to content

Commit fd82561

Browse files
Merge pull request #23 from FireTail-io/hotfix/close-race
Hotfix/close race
2 parents 500b829 + e3006c0 commit fd82561

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

logsapi/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (c *Client) Start(ctx context.Context) error {
5353
if err != http.ErrServerClosed {
5454
err = errors.WithMessage(err, "Log server closed unexpectedly")
5555
c.errCallback(err)
56-
c.Shutdown(ctx)
5756
} else if err != nil {
5857
c.errCallback(err)
5958
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ func main() {
5555

5656
// Sleep for 500ms to allow any final logs to be sent to the extension by the Lambda Logs API
5757
log.Printf("Sleeping for 500ms to allow final logs to be processed...")
58-
time.Sleep(500)
58+
time.Sleep(500 * time.Millisecond)
5959
}

main_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"net/http/httptest"
77
"strings"
88
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/assert"
912
)
1013

1114
func TestMain(t *testing.T) {
@@ -32,3 +35,19 @@ func TestMainDebug(t *testing.T) {
3235

3336
main()
3437
}
38+
39+
func TestMainReturnsInNoLessThan500Milliseconds(t *testing.T) {
40+
http.DefaultServeMux = new(http.ServeMux)
41+
mockExtensionsApi := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
42+
fmt.Fprintf(w, `{"eventType": "SHUTDOWN"}`)
43+
}))
44+
defer mockExtensionsApi.Close()
45+
46+
t.Setenv("AWS_LAMBDA_RUNTIME_API", strings.Join(strings.Split(mockExtensionsApi.URL, ":")[1:], ":")[2:])
47+
48+
startTime := time.Now()
49+
50+
main()
51+
52+
assert.Greater(t, time.Since(startTime), 500*time.Millisecond)
53+
}

0 commit comments

Comments
 (0)