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

consul monitor doesn't respond to SIGINT/TERM until initial log lines come in #3891

Closed
c4milo opened this issue Feb 15, 2018 · 11 comments
Closed
Assignees
Labels
type/bug Feature does not function as expected
Milestone

Comments

@c4milo
Copy link
Contributor

c4milo commented Feb 15, 2018

When running consul monitor on machines with acl tokens without enough privileges, it blocks forever and doesn't respond to SIGINT or SIGTERM signals.

Reproduction steps

  1. Provision a Consul cluster with ACLs enabled
  2. Create an ACL token without permissions to see other nodes
  3. Run a client agent with token created in 2.
  4. Run consul monitor

Expected behavior

Exit immediately with a message indicating the lack of permissions.

consul version for both Client and Server

Client: v1.0.6
Server: v1.0.6

@banks
Copy link
Member

banks commented Feb 15, 2018

I think the ACL part is even a red-herring I just tested master locally and consul monitor doesn't respond to SIGINT even with ACLs disabled on the agent.

I've edited the title to make the scope clearer.

Thanks for the report!

@banks banks added the type/bug Feature does not function as expected label Feb 15, 2018
@banks banks changed the title consul monitor blocks forever when ACL token doesn't have enough privileges. consul monitor doesn't respond to SIGINT Feb 15, 2018
@banks
Copy link
Member

banks commented Feb 15, 2018

Breadcrumbs: note that we do register monitor for shutdown handling here:

Register("monitor", func(ui cli.Ui) (cli.Command, error) { return monitor.New(ui, MakeShutdownCh()), nil })

And that includes os.Interrupt and syscall.SIGTERM:

signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)

@banks banks changed the title consul monitor doesn't respond to SIGINT consul monitor doesn't respond to SIGINT/TERM until initial log lines come in Feb 15, 2018
@banks
Copy link
Member

banks commented Feb 15, 2018

It seems that this only happens when there is no output yet. In my case there was only debug events in the log and i wasn't useing debug level so it hung uninteruptible. As soon as I allow DEBUG level I saw logs and Ctrl-C works fine.

In your case here @c4milo the ACL issue prevents any logs from ever being fetched causing same issue.

@banks banks added this to the Next milestone Feb 15, 2018
@banks banks self-assigned this Feb 15, 2018
@banks
Copy link
Member

banks commented Feb 19, 2018

This is caused by the call to the monitor API here:

logCh, err := client.Agent().Monitor(c.logLevel, eventDoneCh, nil)

Being made before shutdownCh is being selected on.

In turn the agent calls the monitor API which effectively blocks until some matching log lines come in:

~/s/g/s/g/h/consul (fix-monitor-sigint-3891 ⚡☡=) curl -v 'localhost:8500/v1/agent/monitor?loglevel=ERR'
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8500 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8500 (#0)
> GET /v1/agent/monitor?loglevel=ERR HTTP/1.1
> Host: localhost:8500
> User-Agent: curl/7.54.0
> Accept: */*
>
^C⏎

Note that not even response headers were returned immediately. It seems like it would be a nicer API for a streaming response to have the headers return immediately and the the body only stream in as there is content. That seems to be what our own client is expecting.

PR incoming.

@banks banks closed this as completed in de58eb1 Feb 21, 2018
banks added a commit that referenced this issue Feb 21, 2018
Fixes #3891: agent monitor no longer unresponsive before logs stream.
@c4milo
Copy link
Contributor Author

c4milo commented Feb 21, 2018

Nice! thank you @banks!

@banks
Copy link
Member

banks commented Feb 22, 2018

@c4milo just checking that did actually fix you're issue right? I think the ACL thin was unrelated but just wanted to check!

@c4milo
Copy link
Contributor Author

c4milo commented Feb 28, 2018

@banks, I haven't had a chance to build a custom binary with this fix yet, I'll report back once I can do that. In the mean time, I believe you missed adding an entry in the CHANGELOG :)

@banks
Copy link
Member

banks commented Feb 28, 2018

Great catch @c4milo thanks ;)

@MichaelSteffens
Copy link

It looks like this fix is almost the same as the one proposed with #3695 last November, attempting to fix #3317 submitted in July. So presumably these can both be closed now.

@banks
Copy link
Member

banks commented Apr 30, 2018

@MichaelSteffens good catch yep those are all obsolete here now thanks.

@MichaelSteffens
Copy link

Confirmed: As expected this fix does also fix #3317. @banks thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Feature does not function as expected
Projects
None yet
Development

No branches or pull requests

3 participants