Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions internal/handlers/get_state_workaround.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/steemit/jussi/internal/request"
"github.com/steemit/jussi/internal/upstream"
"github.com/steemit/jussi/internal/urn"
)

Expand Down Expand Up @@ -628,14 +627,7 @@ func (p *RequestProcessor) callSteemd(
}
headers := originalReq.UpstreamHeaders()

retryCfg := &upstream.RetryConfig{
MaxRetries: 1,
InitialBackoff: 100 * time.Millisecond,
MaxBackoff: 1 * time.Second,
BackoffMultiplier: 2.0,
}

return p.httpClient.RequestWithRetry(subCtx, upstreamURL, payload, headers, retryCfg)
return p.httpClient.Request(subCtx, upstreamURL, payload, headers)
}

// deepCopyMap creates a deep copy of a map[string]interface{} by
Expand Down
12 changes: 8 additions & 4 deletions internal/handlers/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,16 @@ func (p *RequestProcessor) callHTTPUpstream(ctx context.Context, jsonrpcReq *req
headers := jsonrpcReq.UpstreamHeaders()

// Create timeout context
// A timeout of 0 in the upstream config means "use default".
// Previously 0 meant "no timeout" which could cause requests to
// hang indefinitely (e.g. broadcast_transaction_synchronous).
timeout := time.Duration(jsonrpcReq.Upstream.Timeout) * time.Second
if timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
if timeout == 0 {
timeout = 3 * time.Second // safe default for all requests
}
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()

return p.httpClient.Request(ctx, url, payload, headers)
}
Expand Down
28 changes: 8 additions & 20 deletions internal/upstream/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,12 @@ func NewHTTPClient() *HTTPClient {
}
}

// Request sends an HTTP POST request to upstream
// Request sends an HTTP POST request to upstream (fail-fast, no retry).
// As a proxy/routing layer, jussi should return errors immediately and
// let the caller decide whether to retry. Retrying at the proxy level
// is dangerous for non-idempotent requests (e.g. broadcast_transaction)
// and adds latency for all requests.
func (c *HTTPClient) Request(ctx context.Context, url string, payload map[string]interface{}, headers map[string]string) (map[string]interface{}, error) {
return c.RequestWithRetry(ctx, url, payload, headers, nil)
}

// RequestWithRetry sends an HTTP POST request to upstream with retry logic
func (c *HTTPClient) RequestWithRetry(ctx context.Context, url string, payload map[string]interface{}, headers map[string]string, retryConfig *RetryConfig) (map[string]interface{}, error) {
if retryConfig == nil {
retryConfig = DefaultRetryConfig()
}

return RetryWithResult(ctx, retryConfig, func() (map[string]interface{}, error) {
return c.doRequest(ctx, url, payload, headers)
})
}

// doRequest performs a single HTTP request
func (c *HTTPClient) doRequest(ctx context.Context, url string, payload map[string]interface{}, headers map[string]string) (map[string]interface{}, error) {
// Marshal payload
body, err := json.Marshal(payload)
if err != nil {
Expand Down Expand Up @@ -80,13 +68,13 @@ func (c *HTTPClient) doRequest(ctx context.Context, url string, payload map[stri
// Send request
resp, err := c.client.Do(req)
if err != nil {
return nil, &RetryableError{Err: fmt.Errorf("request failed: %w", err)}
return nil, fmt.Errorf("upstream request failed: %w", err)
}
defer resp.Body.Close()

// Check for retryable status codes
// Check for server errors
if resp.StatusCode >= 500 {
return nil, &RetryableError{Err: fmt.Errorf("server error: %d", resp.StatusCode)}
return nil, fmt.Errorf("upstream server error: %d", resp.StatusCode)
}

// Read response
Expand Down
150 changes: 0 additions & 150 deletions internal/upstream/retry.go

This file was deleted.

Loading