Skip to content

Commit 8c64762

Browse files
committed
Revert "Use context for HTTP timeouts rather than set at the client level, enabling robust cancelation and propagation"
This reverts commit 18ebbe2.
1 parent cfe6e3e commit 8c64762

10 files changed

Lines changed: 18 additions & 53 deletions

File tree

cmd/account.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/runware/runware-cli/internal/api"
@@ -24,11 +25,8 @@ var accountCreditsCmd = &cobra.Command{
2425
return api.ErrNoAPIKey
2526
}
2627

27-
ctx, cancel := contextWithTimeout(cmd)
28-
defer cancel()
29-
3028
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
31-
result, err := client.AccountDetails(ctx)
29+
result, err := client.AccountDetails(context.Background())
3230
if err != nil {
3331
if api.IsAuthError(err) {
3432
output.Error("Authentication failed. Run 'runware auth login' to set your API key.")

cmd/audio_inference.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ func runAudioInference(cmd *cobra.Command, args []string) error {
150150
}
151151

152152
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
153-
154-
ctx, cancel := contextWithTimeout(cmd)
155-
defer cancel()
156-
157-
_, err := client.AudioInference(ctx, req)
153+
_, err := client.AudioInference(context.Background(), req)
158154
if err != nil {
159155
if s != nil {
160156
s.Stop()
@@ -177,7 +173,7 @@ func runAudioInference(cmd *cobra.Command, args []string) error {
177173
var results []api.AudioInferenceResult
178174

179175
for time.Now().Before(deadline) {
180-
rawData, err := client.GetResponse(ctx, taskUUID)
176+
rawData, err := client.GetResponse(context.Background(), taskUUID)
181177
if err != nil {
182178
if flagVerbose {
183179
fmt.Fprintf(os.Stderr, "Poll: %s\n", err) //nolint:errcheck,gosec

cmd/auth.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"bufio"
5+
"context"
56
"fmt"
67
"os"
78
"strings"
@@ -49,9 +50,7 @@ var authLoginCmd = &cobra.Command{
4950

5051
// Validate key by pinging the API
5152
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
52-
ctx, cancel := contextWithTimeout(cmd)
53-
defer cancel()
54-
_, err := client.Ping(ctx)
53+
_, err := client.Ping(context.Background())
5554
if err != nil {
5655
output.Error("Invalid API key. Authentication failed.")
5756
return err
@@ -94,10 +93,8 @@ var authStatusCmd = &cobra.Command{
9493
if key != "" {
9594
maskedKey = config.MaskKey(key)
9695
// Verify the key
97-
ctx, cancel := contextWithTimeout(cmd)
98-
defer cancel()
9996
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
100-
_, err := client.Ping(ctx)
97+
_, err := client.Ping(context.Background())
10198
if err != nil {
10299
status = "invalid"
103100
} else {

cmd/common.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

cmd/model_search.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"strings"
67

@@ -66,11 +67,8 @@ func runModelSearch(cmd *cobra.Command, args []string) error {
6667
req.Offset = v
6768
}
6869

69-
ctx, cancel := contextWithTimeout(cmd)
70-
defer cancel()
71-
7270
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
73-
result, err := client.ModelSearch(ctx, req)
71+
result, err := client.ModelSearch(context.Background(), req)
7472
if err != nil {
7573
if api.IsAuthError(err) {
7674
output.Error("Authentication failed. Run 'runware auth login' to set your API key.")

cmd/ping.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"time"
67

@@ -22,11 +23,8 @@ var pingCmd = &cobra.Command{
2223

2324
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
2425

25-
ctx, cancel := contextWithTimeout(cmd)
26-
defer cancel()
27-
2826
start := time.Now()
29-
_, err := client.Ping(ctx)
27+
_, err := client.Ping(context.Background())
3028
if err != nil {
3129
if api.IsAuthError(err) {
3230
output.Error("Authentication failed. Run 'runware auth login' to set your API key.")

cmd/root.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package cmd
22

33
import (
4-
"context"
54
"fmt"
65
"os"
7-
"time"
86

97
"github.com/runware/runware-cli/internal/config"
108
"github.com/spf13/cobra"
@@ -42,7 +40,6 @@ func init() {
4240
rootCmd.PersistentFlags().StringVar(&flagFormat, "format", "", "Output format: table, json, yaml")
4341
rootCmd.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "Show request/response details")
4442
rootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "Show full debug output")
45-
rootCmd.PersistentFlags().Int("request-timeout", defaultRequestTimeoutSeconds, "HTTP request timeout in seconds (0 = no timeout)")
4643

4744
rootCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) { //nolint:errcheck,gosec
4845
return []cobra.Completion{"table", "json", "yaml"}, cobra.ShellCompDirectiveNoFileComp
@@ -77,13 +74,3 @@ func getFormat() string {
7774
}
7875
return config.Get().Defaults.Format
7976
}
80-
81-
// contextWithTimeout builds a context from the cobra command's context,
82-
// applying --request-timeout if set (0 = no timeout).
83-
func contextWithTimeout(cmd *cobra.Command) (context.Context, context.CancelFunc) {
84-
secs, _ := cmd.Flags().GetInt("request-timeout")
85-
if secs <= 0 {
86-
return context.WithCancel(cmd.Context())
87-
}
88-
return context.WithTimeout(cmd.Context(), time.Duration(secs)*time.Second)
89-
}

cmd/text_inference.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"os"
@@ -147,11 +148,8 @@ func runTextInference(cmd *cobra.Command, args []string) error {
147148
s.Start()
148149
}
149150

150-
ctx, cancel := contextWithTimeout(cmd)
151-
defer cancel()
152-
153151
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
154-
results, err := client.TextInference(ctx, req)
152+
results, err := client.TextInference(context.Background(), req)
155153

156154
if s != nil {
157155
s.Stop()

cmd/video_inference.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ func runVideoInference(cmd *cobra.Command, args []string) error {
199199
}
200200

201201
client := api.NewClient(key, config.GetBaseURL(), flagVerbose)
202-
203-
ctx, cancel := contextWithTimeout(cmd)
204-
defer cancel()
205-
206-
submitResults, err := client.VideoInference(ctx, req)
202+
submitResults, err := client.VideoInference(context.Background(), req)
207203

208204
if err != nil {
209205
if s != nil {
@@ -231,7 +227,7 @@ func runVideoInference(cmd *cobra.Command, args []string) error {
231227
var results []api.VideoInferenceResult
232228

233229
for time.Now().Before(deadline) {
234-
rawData, err := client.GetResponse(ctx, taskUUID)
230+
rawData, err := client.GetResponse(context.Background(), taskUUID)
235231
if err != nil {
236232
// getResponse may return an error if results aren't ready yet — keep polling
237233
if flagVerbose {

internal/api/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ func NewClient(apiKey, baseURL string, verbose bool) *RestClient {
4141
apiKey: apiKey,
4242
baseURL: baseURL,
4343
verbose: verbose,
44-
httpClient: &http.Client{},
44+
httpClient: &http.Client{
45+
Timeout: 120 * time.Second,
46+
},
4547
}
4648
}
4749

0 commit comments

Comments
 (0)