Cancelable ReadDirContext#565
Conversation
| return entries, err | ||
| } | ||
| id := c.nextID() | ||
| typ, data, err1 := c.sendPacket(nil, &sshFxpReaddirPacket{ |
There was a problem hiding this comment.
This creates internally a channel, that is used to waiting on for a response from the server. https://github.com/pkg/sftp/blob/master/conn.go#L131
Instead we would want to use dispatchRequest and then we can:
select {
case <-ctx.Done():
return entries, err
case result := <-ch:
typ, data, err1 = s.typ, s.data, s.err
}
Otherwise, we’re going to be stuck until the server responds with at least one sshFxpName packet.
There was a problem hiding this comment.
Right, I have added the context to opendir and sendPacket
|
Hm… probably not the change I would have made… but probably a change for the better… 🤔 P.S.: That is to say, I would have limited the scope of the change rather than plumb a context everywhere. But then, the context should probably be there anyways, so. 🤷♀️ |
|
It has become a reflex to add ctx everywhere. So far it never turned out that there were too many ctx in any code base, if there were problems then because of not enough ctx ;-) |
|
But I can rewrite the PR if you want... |
|
No, there is no need to rewrite, I don’t think the plumbed context will cause any performance issues. |
Added method
Client.ReadDirContextto be able to cancel long-running dir listings.The passed context can cancel the operation returning all entries listed up to the cancellation.