fix regex, remove unsafe pointer usage, and add graceful HTTP shutdown
- Fix versionMatcher regex: gorilla/mux does not support (?:) syntax, and -dirty suffix was required instead of optional - Replace unsafe.Pointer LUN casts with binary.LittleEndian.Uint64 in sbc.go, scsi.go, and target.go - Implement graceful HTTP server shutdown with 5s timeout using srv.Shutdown() instead of raw listener close - Replace golang.org/x/net/context with standard library context - Respect existing req.Cancel value in canceler to avoid overwriting - Add early context cancellation check in Do() to fail fast Based on review of PR #120 by @orzhang, with fixes applied. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,10 @@ import (
|
||||
)
|
||||
|
||||
func canceler(client transport.Sender, req *http.Request) func() {
|
||||
// TODO(djd): Respect any existing value of req.Cancel.
|
||||
// Respect any existing value of req.Cancel.
|
||||
if req.Cancel != nil {
|
||||
return nop
|
||||
}
|
||||
ch := make(chan struct{})
|
||||
req.Cancel = ch
|
||||
|
||||
|
||||
@@ -35,6 +35,13 @@ func Do(ctx context.Context, client transport.Sender, req *http.Request) (*http.
|
||||
client = http.DefaultClient
|
||||
}
|
||||
|
||||
// If the context is already done, return early.
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
default:
|
||||
}
|
||||
|
||||
// Request cancelation changed in Go 1.5, see canceler.go and canceler_go14.go.
|
||||
cancel := canceler(client, req)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user