Skip to content

Commit c6837ec

Browse files
authored
feat: improve graphsync transport logging (#238)
1 parent e69ae98 commit c6837ec

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

transport/graphsync/graphsync.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,31 @@ func (t *Transport) OpenChannel(ctx context.Context,
166166

167167
// Read from the graphsync response and error channels until they are closed,
168168
// and return the last error on the error channel
169-
func (t *Transport) consumeResponses(responseChan <-chan graphsync.ResponseProgress, errChan <-chan error) error {
169+
func (t *Transport) consumeResponses(req *gsReq) error {
170170
var lastError error
171-
for range responseChan {
171+
for range req.responseChan {
172172
}
173-
for err := range errChan {
173+
log.Infof("channel %s: finished consuming graphsync response channel", req.channelID)
174+
175+
for err := range req.errChan {
174176
lastError = err
175177
}
178+
log.Infof("channel %s: finished consuming graphsync error channel", req.channelID)
179+
176180
return lastError
177181
}
178182

179183
// Read from the graphsync response and error channels until they are closed
180184
// or there is an error, then call the channel completed callback
181185
func (t *Transport) executeGsRequest(req *gsReq) {
186+
// Make sure to call the onComplete callback before returning
182187
defer func() {
183188
log.Infow("gs request complete for channel", "chid", req.channelID)
184189
req.onComplete()
185190
}()
186191

187-
lastError := t.consumeResponses(req.responseChan, req.errChan)
192+
// Consume the response and error channels for the graphsync request
193+
lastError := t.consumeResponses(req)
188194

189195
// Request cancelled by client
190196
if _, ok := lastError.(graphsync.RequestClientCancelledErr); ok {
@@ -198,19 +204,20 @@ func (t *Transport) executeGsRequest(req *gsReq) {
198204

199205
// Request cancelled by responder
200206
if _, ok := lastError.(graphsync.RequestCancelledErr); ok {
207+
log.Infof("channel %s: graphsync request cancelled by responder", req.channelID)
201208
// TODO Should we do anything for RequestCancelledErr ?
202209
return
203210
}
204211

205212
if lastError != nil {
206-
log.Warnf("graphsync error on channel %s: %s", req.channelID, lastError)
213+
log.Warnf("channel %s: graphsync error: %s", req.channelID, lastError)
207214
}
208215

209-
log.Debugf("finished executing graphsync request for channel %s", req.channelID)
216+
log.Debugf("channel %s: finished executing graphsync request", req.channelID)
210217

211218
var completeErr error
212219
if lastError != nil {
213-
completeErr = xerrors.Errorf("graphsync request failed to complete: %w", lastError)
220+
completeErr = xerrors.Errorf("channel %s: graphsync request failed to complete: %w", req.channelID, lastError)
214221
}
215222

216223
// Used by the tests to listen for when a request completes
@@ -220,7 +227,7 @@ func (t *Transport) executeGsRequest(req *gsReq) {
220227

221228
err := t.events.OnChannelCompleted(req.channelID, completeErr)
222229
if err != nil {
223-
log.Errorf("processing OnChannelCompleted %s: %s", req.channelID, err)
230+
log.Errorf("channel %s: processing OnChannelCompleted: %s", req.channelID, err)
224231
}
225232
}
226233

0 commit comments

Comments
 (0)