Skip to content

Commit f2a9a7b

Browse files
committed
don't defer closing the response writer
Closing the response writer signifies to the Compute runtime that the response has been successfully completed, so we shouldn't defer it in case the handler panics. In TinyGo, defers aren't run after panic so this wasn't executed. In Go, defers are run. The result of this was that if a handler panicked before sending a response, it would send an empty 200 OK response in Go but a 500 Internal Server Error in TinyGo. Fixes #98.
1 parent a330904 commit f2a9a7b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fsthttp/handle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func Serve(h Handler) {
3535
}
3636
})
3737

38-
defer clientResponseWriter.Close()
3938
h.ServeHTTP(ctx, clientResponseWriter, clientRequest)
39+
clientResponseWriter.Close()
4040
}
4141

4242
// ServeFunc is sugar for Serve(HandlerFunc(f)).

0 commit comments

Comments
 (0)