Skip to content

Commit

Permalink
Properly define timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Oct 28, 2022
1 parent a1adbd3 commit de5c9c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ You can also use it to test and develop the source code:
nix develop # drops you in a shell with all the thing needed
nix flake check # runs tests
```

### System Services

System Service example file for macOS and Linux is available in the [misc](./misc) directory.
Expand Down
17 changes: 9 additions & 8 deletions gosmee/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ accessible endpoint and forward request to your local service`,
decorate = false
}
cfg := goSmee{
smeeURL: smeeURL,
targetURL: targetURL,
saveDir: c.String("saveDir"),
noReplay: c.Bool("noReplay"),
decorate: decorate,
ignoreEvents: c.StringSlice("ignore-event"),
channel: c.String("channel"),
smeeURL: smeeURL,
targetURL: targetURL,
saveDir: c.String("saveDir"),
noReplay: c.Bool("noReplay"),
decorate: decorate,
ignoreEvents: c.StringSlice("ignore-event"),
channel: c.String("channel"),
targetCnxTimeout: c.Int("target-connection-timeout"),
}
err := cfg.clientSetup()
return err
Expand All @@ -121,7 +122,7 @@ accessible endpoint and forward request to your local service`,
},
&cli.IntFlag{
Name: "target-connection-timeout",
Usage: "How long to wait for the connection timeout",
Usage: "How long to wait when forwarding the request to the service",
EnvVars: []string{"GOSMEE_TARGET_TIMEOUT"},
Value: defaultTimeout,
},
Expand Down
8 changes: 5 additions & 3 deletions gosmee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type goSmee struct {
decorate, noReplay bool
ignoreEvents []string
channel string
targetCnxTimeout int
}

type payloadMsg struct {
Expand Down Expand Up @@ -230,9 +231,10 @@ func (c goSmee) replayData(b []byte) error {
return nil
}

client := http.Client{Timeout: time.Duration(defaultTimeout) * time.Second}
ctx := context.Background()
req, err := http.NewRequestWithContext(ctx, "POST", c.targetURL, strings.NewReader(string(pm.body)))
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(c.targetCnxTimeout)*time.Second)
defer cancel()
client := http.Client{}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.targetURL, strings.NewReader(string(pm.body)))
if err != nil {
return err
}
Expand Down

0 comments on commit de5c9c0

Please sign in to comment.