Skip to content

Commit 5a1ebf7

Browse files
committed
Update subscription heartbeat handling and logging
1 parent 097167a commit 5a1ebf7

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

v2/pkg/engine/resolve/resolve.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Resolver struct {
6565

6666
propagateSubgraphErrors bool
6767
propagateSubgraphStatusCodes bool
68-
// Multipart heartbeat interval
68+
// Subscription heartbeat interval
6969
heartbeatInterval time.Duration
7070
// maxSubscriptionFetchTimeout defines the maximum time a subscription fetch can take before it is considered timed out
7171
maxSubscriptionFetchTimeout time.Duration
@@ -306,8 +306,8 @@ func (s *sub) startWorker() {
306306
s.startWorkerWithoutHeartbeat()
307307
}
308308

309-
// startWorkerWithHeartbeat is similar to startWorker but sends heartbeats to the client when
310-
// subscription over multipart is used. It sends a heartbeat to the client every heartbeatInterval.
309+
// startWorkerWithHeartbeat is similar to startWorker but sends heartbeats to the client when enabled.
310+
// It sends a heartbeat to the client every heartbeatInterval. Heartbeats are handled by the SubscriptionResponseWriter interface.
311311
// TODO: Implement a shared timer implementation to avoid creating a new ticker for each subscription.
312312
func (s *sub) startWorkerWithHeartbeat() {
313313
heartbeatTicker := time.NewTicker(s.resolver.heartbeatInterval)
@@ -515,16 +515,13 @@ func (r *Resolver) handleHeartbeat(sub *sub) {
515515
}
516516

517517
if err := sub.writer.Heartbeat(); err != nil {
518-
if errors.Is(err, context.Canceled) {
519-
// If Write fails (e.g. client disconnected), remove the subscription.
520-
_ = r.AsyncUnsubscribeSubscription(sub.id)
521-
return
522-
}
523-
r.asyncErrorWriter.WriteError(sub.ctx, err, nil, sub.writer)
518+
// If heartbeat fails (e.g. client disconnected), remove the subscription.
519+
_ = r.AsyncUnsubscribeSubscription(sub.id)
520+
return
524521
}
525522

526523
if r.options.Debug {
527-
fmt.Printf("resolver:heartbeat:subscription:flushed:%d\n", sub.id.SubscriptionID)
524+
fmt.Printf("resolver:heartbeat:subscription:done:%d\n", sub.id.SubscriptionID)
528525
}
529526

530527
if r.reporter != nil {

0 commit comments

Comments
 (0)