Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the process of upgrading the ckb dependency, I encountered the problem that the unit test did not pass after the upgrade, and after spending about two days locating and fixing it, I produced this PR.
First of all, the problem arises when the upgrade process incorrectly implements a trait, which happens with ckb's ping protocol:
This implementation causes the future generated by this method to be called uninterruptedly, which is not a big problem when a runtime starts a network, but when multiple networks are created at the same time, all workers will be stuck in this future and other tasks will not be executed, which causes the unit tests of the network module to fail extensively, but the integration tests pass entirely.
In rust's collaborative asynchronous model, the problem of user implementation errors is hard to cure, but as a framework, we have to make the implementation work as well as possible, so I introduced tokio's budget model, which takes the framework's controllable future and adds the logic of forced yield to make it work as well as possible even in exception states. Since we don't have a need to disable it, the implementation is simpler than tokio.
The ckb network unit test passes 100% even in the bad implementation(ping protocol impl with
Some(())
).There are many ways to implement the budget.
Another bug fixed in the implementation of poll fn, which does not call it if it returns none, as the documentation says
Remove the external exposure of socket2, so that external interaction is only possible via fd