v0.19: HTTP bug fixes #1503
Labels
No labels
UX
active development
backlog
blocker
bootstrap
bounty
bug
dependencies
discussion
documentation
duplicate
enhancement
flaky test
help wanted
invalid
javascript
question
release
tendentious
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mighty-gerbils/gerbil!1503
Loading…
Reference in a new issue
No description provided.
Delete branch "jay/gerbil:v0.19-http-bug-fixes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug fixes for HTTP std module:
400for request-head protocol errors without reclassifying application errors.Hostfor HTTP/1.1 and reject duplicate Host fields. Validate decimalContent-Lengthvalues and agreement between duplicates. RejectTransfer-Encoding/Content-Lengthconflicts and unsupported transfer codings; only a singlechunkedcoding is supported.100 Continuebefore body reads for HTTP/1.1 requests with a single case-insensitiveExpect: 100-continuefield and positiveContent-Lengthor chunked framing. Invalid heads receive no acknowledgment; other Expect forms remain ignored.100 Continueresponses and return the final response. Preserve WebSocket101handling.Public request/response structures are unchanged.
Tests
Benchmark
One sequential before/after pair:
f0badc77without this PR’s fixes versus currentb9892378. Verified prebuilt executables were reused; no rebuild was performed for this rerun.Latencies are milliseconds; p95/p99 are the 95th/99th percentiles.
All 14,000 requests, including warmups, returned HTTP 200 with no errors or timeouts. Median latency changes ranged from -6.2% to +2.3% in this pair; p99 decreased across all four workloads. Mean CPU utilization was 5.75% before and 5.70% after. This single fixed-load comparison is not a capacity test or proof of performance neutrality.
WIP: v0.19: HTTP bug fixesto v0.19: HTTP bug fixesI request some changes, the code can become better.
The main request is to have a base error class for the errors that result in 400 so that we don't have to check all of them exhaustively. that's a code quality issue.
I also left some comments about potential optimizations, i think it is worth doing them to avoid some allocations and astra can handle it.
@ -73,0 +86,4 @@(and ;; string-split drops an empty final field after a trailing SP.(not (char=? (string-ref line (fx1- (string-length line))) #\space))(fx> method-length 0)(let loop ((i 0 :- :fixnum))i think a better way to validate the method is to have a statically constructed hash table with method tables and just lookup there, no need to parse it at all. the methods are defined by the standard anyway.
@ -155,0 +242,4 @@where: read-header!)))(validate (fx1+ i))))(cons key(let trim-right ((stop end :- :fixnum))i have the feeling this could be made more efficient by fusing with the header read loop. we could avoid the intermediate string allocation and the substring.
@ -20,0 +19,4 @@new-response-handlervalidate-request-host!request-content-lengthMalformedHostyou can struct-out export all the error classes.
@ -20,0 +26,4 @@MalformedRequestFramingMalformedRequestFraming?)(deferror-class (MalformedHost IOError) ())if all these result to the same error code (400) you can make a base error class and inherit from there. this also goes for the other utility error classes.
@ -281,1 +312,3 @@(cut display-exception e <>))))(try(if (and reading-request-head?(or (MalformedRequestLine? e)here the base error class comes handy, no need for 10 or cases, just check the base class predicate.
@ -73,0 +107,4 @@(char<=? #\0 (string-ref proto 5) #\9)(char=? (string-ref proto 6) #\.)(char<=? #\0 (string-ref proto 7) #\9))(raise/context (MalformedRequestLine "invalid request line" irritants: [line])you should define a raise macro with defraise/context and use it, it handles things nicely and most importantly puts the abort annotation that informs the compiler that it is a computational cut.
same for all the raises of input errors.
@vyzo addressed your feedback. apologies for not reviewing this more before opening, I was on the road earlier and just pushed what I had!
hey no worries, that's what review is for. astra is a great programmer, but still needs some advice.
looks good!