Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail the snapshotter immediately if metrics server can't be bound #363

Merged
merged 1 commit into from
Feb 24, 2023

Conversation

changweige
Copy link
Member

We should fail snapshotter's startup if the metrics address weren't bound.

}
go func() {
if err := http.ListenAndServe(addr, nil); err != nil {
log.L.Errorf("error serve on %s: %v", addr, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make sure to exit snapshotter once http.ListenAndServe fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

Better not to, we should try to maintain the snapshots service , I suppose.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So the user can only determine if the metrics server is working by checking the error log? I think it's a not good design.

Copy link
Member Author

Choose a reason for hiding this comment

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

Um. If we indeed need to ensure that the metrics server is successfully started, perhaps we can try to connect to the listener in the main goroutine

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we just need to move the connection listen out from ListenAndServe. listen is likely to fail when the port is already bound when serve can only fail when the connection is closed by accident

Copy link
Member

Choose a reason for hiding this comment

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

Agree. It is sufficient to quit snapshotter if the port is already bound.

}
go func() {
if err := http.ListenAndServe(addr, nil); err != nil {
log.L.Errorf("error serve on %s: %v", addr, err)
Copy link
Member

@sctb512 sctb512 Feb 20, 2023

Choose a reason for hiding this comment

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

Could we display information such as "Failed to serve metrics HTTP endpoint on %s: %v" as this error message is in a go routine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. We'd better give more information about error context.

@changweige changweige force-pushed the fail-start-metrics-address branch 2 times, most recently from da14195 to 9f7ad26 Compare February 21, 2023 07:11
Copy link
Member

@sctb512 sctb512 left a comment

Choose a reason for hiding this comment

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

LGTM

}

go func() {
log.L.Infof("Start metrics HTTP server on %s", addr)
if err := http.Serve(l, nil); trapClosedConnErr(err) != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps err != nil && !errors.Is(err, net.ErrClosed) will also work?

We'd better to exit from snapshotter's startup if the metrics server
address can't be bound.

Signed-off-by: Changwei Ge <gechangwei@bytedance.com>
@imeoer imeoer merged commit 222d2b1 into containerd:main Feb 24, 2023
@changweige changweige deleted the fail-start-metrics-address branch February 27, 2023 08:20
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.

None yet

3 participants