Skip to content

Added option to disable signal handling by Server.#191

Merged
bboreham merged 6 commits intoweaveworks:masterfrom
pstibrany:disable-signal-handling
May 11, 2020
Merged

Added option to disable signal handling by Server.#191
bboreham merged 6 commits intoweaveworks:masterfrom
pstibrany:disable-signal-handling

Conversation

@pstibrany
Copy link
Contributor

@pstibrany pstibrany commented Apr 30, 2020

In Cortex, we currently have extra logic (as explained here) to handle the fact that server.Server type handles SIGINT/SIGTERM signals, that should trigger shutdown of entire server.

This PR adds ability to disable signal handling by Server. This will make it possible to handle signal by Cortex Run method instead, and to trigger shutdown of all services (incl. Server) cleanly, without doing special hacks for "Server" service.

Option to disable signal handling is deliberately "negative" ("disable", not "enable"), to keep existing code working as before.

Copy link
Contributor

@annanay25 annanay25 left a comment

Choose a reason for hiding this comment

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

Thanks for this change, @pstibrany! I agree with the general direction.

@pstibrany
Copy link
Contributor Author

pstibrany commented May 4, 2020

Any chance of getting this merged?

We would like to know whether we can simplify the design of Cortex modules proposal (if this is accepted), or not.

Thank you very much!

(If any changes are needed, please let me know)

server/server.go Outdated
}()
} else {
go func() {
<-s.quit
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we have many ways to quit now and I don't know why.
Why do we need Stop vs Shutdown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stop vs Shutdown was there before. Run is a blocking method, that returns first error from HTTP/gRPC or nil, if signal has been received or Stop was called.
Shutdown stops gRPC and HTTP servers.

Since Stop works by stopping signal handler, which can no longer be there, I've kept the functionality of Stop by using quit channel.

If we were doing design from scratch, we could replace blocking Run method with non-blocking Start (perhaps returning channel with errors), which would make Stop unnecessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking further, the signal-handler has another Stop() mechanism SignalReceiver, which appears to be impossible to use from Server.

How about making handler something you can pass in config, like Log, that has interface Loop() and Stop(), then Cortex can pass either what you're doing with quit or its own actual signal handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds good, I'll update PR with your suggestion.

@pstibrany
Copy link
Contributor Author

I've updated PR with interface as per suggestion. I've also modified unrelated genCerts.sh to avoid lint complaints (not sure why I'm getting those now).

Copy link
Collaborator

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm

@bboreham bboreham merged commit c4a9ff7 into weaveworks:master May 11, 2020
@pstibrany
Copy link
Contributor Author

Thanks!

@pstibrany pstibrany deleted the disable-signal-handling branch May 11, 2020 09:49
yeya24 pushed a commit to yeya24/common that referenced this pull request Jun 12, 2024
…works#191)

* Implement common file server to return consistent Content-Type

When `/etc/mime.types` has a unusual mime type, Content-Type of response becomes the type and you may get unexpected result.
This server returns consistent Content-Type header for js and css files

Signed-off-by: mrasu <m.rasu.hitsuji@gmail.com>
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.

3 participants