Skip to content

[Network] Middleware component#1355

Merged
bors[bot] merged 53 commits intomasterfrom
smnzhu/middleware-component
Oct 12, 2021
Merged

[Network] Middleware component#1355
bors[bot] merged 53 commits intomasterfrom
smnzhu/middleware-component

Conversation

@synzhu
Copy link
Copy Markdown
Contributor

@synzhu synzhu commented Sep 26, 2021

  • Refactor middleware to implement the Component interface.
  • Introduces new ComponentManager struct to help implement Component interface
  • Various refactoring in network layer and scaffold to enable the changes above.

TODO

  • As mentioned in [FLIP] Component API #1167 (comment), we should probably explicitly throw an error when Start is called multiple times, instead of simply ignoring subsequent calls
  • Update the godoc for Startable to reflect this
  • Add tests for ComponentManager

@synzhu synzhu changed the base branch from master to smnzhu/error-handling September 26, 2021 20:43
Copy link
Copy Markdown
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is looking great! could use some comments, particularly in common.go

@peterargue peterargue mentioned this pull request Sep 28, 2021
1 task
Base automatically changed from smnzhu/error-handling to master September 29, 2021 04:55
@synzhu synzhu requested a review from peterargue September 30, 2021 02:30
Copy link
Copy Markdown
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome! Thank you so much for documenting the channel logic in RunComponent and the ComponentManager's Start, and the ErrorHandlingResult in particular is 👌

I suspect a "further work" task may be to add a runnable example.


func NewSignaler(errors chan<- error) *Signaler {
return &Signaler{errors}
func NewSignaler() (*Signaler, <-chan error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is cleaner

// the One True Way of getting a SignalerContext
func WithSignaler(ctx context.Context, sig *Signaler) SignalerContext {
return signalerCtxt{ctx, sig}
func WithSignaler(parent context.Context) (SignalerContext, <-chan error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like that this is consistent with other With* context methods


type ReadyFunc func()

// ComponentWorker represents a worker routine of a component
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some more details here so implementors know how this should be used. I think we've discussed adding general worker routines as well as subcomponent startup logic and kicking off shutdown handlers.

defer close(c.done)

// throw fatal error during startup
ctx.Throw(ErrFatal)
Copy link
Copy Markdown
Contributor

@peterargue peterargue Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if this is thrown outside of the goroutine? that would exit the routine calling RunComponent right? which would bypass the error handler. maybe we need to either call the start method in it's own goroutine, or explicitly call out in the comments for RunComponent that throw should only be called within a subroutine

@synzhu
Copy link
Copy Markdown
Contributor Author

synzhu commented Oct 9, 2021

@peterargue addrssed comments

@synzhu synzhu requested a review from peterargue October 11, 2021 17:09
Copy link
Copy Markdown
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work!

@synzhu
Copy link
Copy Markdown
Contributor Author

synzhu commented Oct 12, 2021

bors merge

bors bot added a commit that referenced this pull request Oct 12, 2021
1355: [Network] Middleware component r=smnzhu a=smnzhu

* Refactor middleware to implement the `Component` interface.
* Introduces new `ComponentManager` struct to help implement `Component` interface
* Various refactoring in network layer and scaffold to enable the changes above.

### TODO

- [x] As mentioned in #1167 (comment), we should probably explicitly throw an error when `Start` is called multiple times, instead of simply ignoring subsequent calls
- [x] Update the godoc for Startable to reflect this
- [x] Add tests for ComponentManager

Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Oct 12, 2021

Build failed:

@synzhu
Copy link
Copy Markdown
Contributor Author

synzhu commented Oct 12, 2021

bors retry

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Oct 12, 2021

@bors bors bot merged commit 361ba2d into master Oct 12, 2021
@bors bors bot deleted the smnzhu/middleware-component branch October 12, 2021 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants