-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Summary
The rpcserver context helpers have two concrete issues:
- Two functions panic on missing values
- Inconsistent error-handling across getters
Bug 1: Panics
// jsonrpc_server.go:432 - PANICS if sizeKey not in context
func GetRequestSize(ctx context.Context) int {
return ctx.Value(sizeKey{}).(int)
}
// jsonrpc_server.go:436 - PANICS if urlKey not in context
func GetURL(ctx context.Context) *url.URL {
return ctx.Value(urlKey{}).(*url.URL)
}Call these outside a handler (e.g., in a test, a goroutine, or refactored code path) and they crash.
Bug 2: Inconsistent Contracts
| Function | Missing Value Behavior |
|---|---|
GetHighPriority |
Returns false |
GetSigner |
Returns zero address |
GetRequest |
Returns nil |
GetBuilderNetSentAt |
Returns zero time |
GetRequestSize |
Panics |
GetURL |
Panics |
Callers can't know which are safe without reading source.
Proposed Fix
Replace context.Value() getters with a typed wrapper (like Gin/Echo):
type RPCContext struct {
Request *http.Request // guaranteed non-nil
URL *url.URL // guaranteed non-nil
RequestSize int
Signer common.Address
// ...
}
func (h *Handler) Method(rctx *RPCContext, args Args) (Result, error) {
rctx.Request.Header.Get("X-Foo") // always safe
}No panics, no magic keys, explicit contracts.
Why Now
Hit this adding header logging across services. Every call site needed nil checks or risked panics. The current design makes simple tasks error-prone.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels