Skip to content

Commit 7ae33e8

Browse files
authored
fix: don't cancel context if in async mode (#398)
1 parent 2a67995 commit 7ae33e8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ spec:
4545
Once the controller reconciled the receiver it will be registered in the proxy which by default processes incoming requests at port `8080`.
4646
Each receiver will receive its own dedicated http path to which webhooks can be send to. See `.status.webhookPath`.
4747
Usually the webhook-controller is exposed via an ingress. In this case the the webhooks must sent to `http://ingress-host/hooks/ixuxbmoofkiq9s2l61h6i2sl6hdgwnud`.
48+
4849
**Note**: The webhookPath will not change anymore once it was set.
4950

50-
```
51+
```yaml
5152
apiVersion: webhook.infra.doodle.com/v1beta1
5253
kind: Receiver
5354
metadata:

internal/proxy/http.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ func (h *HttpProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
124124
responses := make(chan *http.Response)
125125

126126
ctx := context.TODO()
127-
var cancel context.CancelFunc
128-
129-
if receiver.Timeout > 0 {
130-
ctx, cancel = context.WithTimeout(ctx, receiver.Timeout)
131-
defer cancel()
132-
}
133127

134128
h.log.Info("clone request to upstreams", "targets", len(receiver.Targets), "request", r.RequestURI)
135129

@@ -139,6 +133,18 @@ func (h *HttpProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
139133
return
140134
}
141135

136+
var cancel context.CancelFunc
137+
shouldCancel := true
138+
if receiver.Timeout > 0 {
139+
ctx, cancel = context.WithTimeout(ctx, receiver.Timeout)
140+
}
141+
142+
defer func() {
143+
if cancel != nil && shouldCancel {
144+
cancel()
145+
}
146+
}()
147+
142148
for _, dst := range receiver.Targets {
143149
h.wg.Add(1)
144150

@@ -171,6 +177,7 @@ func (h *HttpProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
171177
}
172178

173179
if receiver.ResponseType == Async {
180+
shouldCancel = false
174181
h.log.Info("return response", "request", r.RequestURI, "status", http.StatusAccepted)
175182
w.WriteHeader(http.StatusAccepted)
176183
return

0 commit comments

Comments
 (0)