filecoin-project / go-legs

Does the legwork for go-data-transfer
Apache License 2.0
20 stars 14 forks source link

Do not call blockhook on partial HTTP errors #153

Closed masih closed 2 years ago

masih commented 2 years ago

The walkfetch logic in httpsync used named return variables. It then used a defer function to call the block hook with synced CIDs when the return err variable is nil and there is a blockhook.

The issue was that the error variable was not being set in some of the execution paths. It was also shadowed internally by the read-opener which made the implementation error prone.

The fix here avoids all of that by removing the named return variables, and explicitly returning the list of synced CIDs which are then passed onto the block hook if there is no error returned. That change guarantees that blockhook will never be called if an error occurs during walkfetch and makes the implementation less prone to accidental shadowing of named return variables.