Commit Graph

145 Commits

Author SHA1 Message Date
Tyler Treat
2ed9c64f66 Merge branch 'master' of github.com:nats-io/gnatsd into enable_config_reload 2017-06-28 14:42:11 -05:00
Tyler Treat
901a5c7122 Address CR feedback 2017-06-28 11:05:02 -05:00
Tyler Treat
dd3ad77ea8 Replace reloaded varz field with config_load_time 2017-06-27 14:33:06 -05:00
Tyler Treat
9adfae11a2 Add reload count to server for monitoring 2017-06-23 10:03:01 -05:00
Tyler Treat
d60085d7c3 Replace mpay locking with atomic 2017-06-22 16:17:31 -05:00
Tyler Treat
b898b5561a Add reload support for pid_file, max_control_line, and max_payload 2017-06-22 14:48:40 -05:00
Tyler Treat
56ab619498 First pass at implementing cluster reload 2017-06-16 15:53:07 -05:00
Peter Miron
00744ff426 converted MonitorAddr and ClusterAddr to *net.TCPAddr 2017-06-12 17:40:36 -04:00
Peter Miron
606502091c Updated based on @tylertreat feedback. 2017-06-12 10:48:30 -04:00
Peter Miron
5e640f099d clean up of log files. removed FatalError function to make sure I'm minimizing changes to actual server. 2017-06-11 16:20:04 -04:00
Peter Miron
da1cb9abb2 missed go fmt'ing. 2017-06-10 10:39:09 -04:00
Peter Miron
d1f38f38a2 changes to support random ports for clusters and profiler. 2017-06-10 10:35:01 -04:00
Peter Miron
f2a9cc8cb0 fixed go fmt'ing 2017-06-08 11:37:23 -04:00
Peter Miron
43a3f1ef1d cleaned up naming to MonitorAddr instead of HttpPort (as it could be either Http or Https). added test for nil to improve coverage. 2017-06-08 10:46:55 -04:00
Peter Miron
41aa44cd8d Added ability to use random ports to limit unit test port contention. 2017-06-08 10:19:56 -04:00
Tyler Treat
cc30af8ede Address code review feedback 2017-06-05 17:43:42 -05:00
Tyler Treat
c468abd15f Merge branch 'master' of github.com:nats-io/gnatsd into config_reload 2017-06-05 13:41:04 -05:00
Tyler Treat
c8280aaee4 Get rid of defer in Server.getOpts()
Defer adds a bit of overhead which can affect fast-paths.
2017-06-01 11:50:28 -05:00
Tyler Treat
28160f1de2 Remove global logger
gnatsd currently uses a global logger. This can cause some problems
(especially around the config-reload work), but global variables are
also just an anti-pattern in general. The current behavior is
particularly surprising because the global logger is configured through
calls to the Server.

This addresses issue #500 by removing the global logger and making it a
field on Server.
2017-05-31 16:06:31 -05:00
Tyler Treat
9902c3da84 First pass at implementing config reload 2017-05-30 16:18:36 -05:00
Ivan Kozlovic
773b25af85 [FIXED] Shutdown stops http server when started manually
In case one creates a server instance with New() and then starts
the http server manually (s.StartHTTPMonitoring()), calling
s.Shutdown() would not stop the http server because Shutdown()
would return without doing anything if `running` was not true.
This boolean was set to true only in `s.Start()`.

Also added StartMonitoring() to perform the options check and
selectively start http or https server to replace individual calls.
This is useful for NATS Streaming server that will now be able
to call s.StartMonitoring() without having to duplicate code
about options checks and http server code.

This is related to PR #481
2017-05-25 17:01:35 -06:00
Ivan Kozlovic
513c0a0971 [FIXED] Specifying HTTP and HTTPs ports produces unexpected behavior
The server will now print a Fatal error if user tries to configure
both HTTP and HTTPs ports.

Resolves #495
2017-05-24 13:06:04 -06:00
Tyler Treat
fa50a2c145 [FIXED] Authorization Timeout and TLS
When TLS and authorization is enabled, the authorization timeout can
fire during the TLS handshake, causing the server to write the
authorization timeout error string into the client socket, injecting
what becomes bad data into the TLS handshake. This creates misleading
errors on the client such as tls: oversized record received with length
21024.

This moves the authorization timeout scheduling to after the TLS
handshake to avoid the race. This should be safe since TLS has its own
handshake timeout. Added a unit test that fails with the old behavior
and passes with the new. LMK if you can think of a better way to test
this.

Fixes #432
2017-05-17 14:38:02 -05:00
Ivan Kozlovic
09f4b85a66 [ADDED] Ability to get the server's HTTP Handler
This will allow applications (for instance NATS Streaming Server)
to add new endpoints to the NATS http server.

Resolves #480
2017-04-27 16:37:01 -06:00
Derek Collison
f7ba3d175e Correct invocation of misspell with fixes 2017-04-21 09:21:33 -07:00
Derek Collison
76de921f65 Cleanup for Auth 2017-04-20 12:41:48 -07:00
Ivan Kozlovic
5f471b6e7f Replace GetListenEndpoint() with ReadyForConnections()
The RunServer() function (and the various variants)
call Server.Start() in a go-routine, but do not return until
it has verified that the server is ready to accept connections.
To do so, it use GetListenEndpoint() to get a suitable connect
address (replacing "0.0.0.0" or "::" with localhost - important
on Windows). It then creates a raw TCP connection to ensure the
server is started, repeating the process in case of failure up
to 10 seconds.

This PR replaces this with a function that checks that client
listener, and route listener if configured, are set. This removes
the need to get a connect address and create test tcp connections.

The reason for this change is that NATS Streaming when starting
the NATS Server (unless configured to connect to a remote one)
calls RunServerWithAuth(), which when getting "localhost" from
GetListenEndpoint(), would fail trying to resolve it. This happened
for the NATS Streaming Docker image built with Go 1.7+.
2016-12-09 14:03:45 -07:00
Derek Collison
8fbacaaea1 Cleanup for cluster opts 2016-12-02 14:29:22 -08:00
Waldemar Quevedo
ff2d6d1983 Add function and test for processing sub command args 2016-12-01 18:18:52 -08:00
Ivan Kozlovic
ca268290a6 Perform the check on accept, not in processing CONNECT
This will protect the server from non NATS clients (telnet, etc),
or misbehaving clients that would create the tcp connection but
block before sending the CONNECT.
The drawback is that the client may or may not receive the error
message (in my tests, it was getting only between 10%-20% of times).
2016-12-01 08:48:04 -07:00
Ivan Kozlovic
6bcd324955 [FIXED] Honor max_connections setting
The max_connections config parameter was accepted but the server
would not check this limit when processing client connections.

Resolves #386
2016-11-30 18:20:12 -07:00
Colin Sullivan
ccca711edd Differentiate signal handling for windows.
Windows has limited support for signals, and does not define syscall.SIGUSR1.  Log rotation will be handled differently in windows.

* Add signal.go for all non-windows builds
* Add signal_windows.go for windows builds.

Today, windows looks to be the only platform that does not have syscall.SIGUSR1 defined.
2016-11-22 15:22:34 -07:00
Derek Collison
1c32f28934 Support to reopen file based logs for rotation 2016-11-21 21:55:24 -08:00
Ivan Kozlovic
4997637270 [FIXED] assignment copies lock value for crypto/tls.Config
Running `go vet ./...` with `go 1.7.3` would report the following:

```
server/route.go:342: assignment copies lock value to tlsConfig: crypto/tls.Config contains sync.Once contains sync.Mutex
server/server.go:479: assignment copies lock value to config: crypto/tls.Config contains sync.Once contains sync.Mutex
```

Add a “clone” function while waiting for this to be addressed
by the language itself (https://go-review.googlesource.com/#/c/28075/)
2016-10-20 14:59:29 -06:00
Ivan Kozlovic
8f7f6e9f8b [FIXED] Client certificate verification when verify is true.
Server was incorrectly requiring a client certificate, but not
verifying it.

Resolves #336
2016-08-25 15:33:13 -06:00
Ivan Kozlovic
c543c77c74 Check that 0.0.0.0 or [::] is not returned as a client connect URL 2016-08-17 11:15:05 -06:00
Ivan Kozlovic
82dbb3a5ab [ADDED] Option to not advertise to clients cluster's IPs
By default, a server is now sending to its clients the client URLs
of all servers in the cluster. This allows clients to be able
to reconnect to any server in the cluster even if those clients
were not configured with the list of servers in the cluster.

However, there may be cases where it would make sense to disable
this feature. This now can be done with this option/command line
parameter.

Resolves #322
2016-08-12 19:24:12 -06:00
Derek Collison
a31e6b2b77 Merge pull request #324 from nats-io/fix_route_ipv6
[FIXED] Cluster's listener with IPv6
2016-08-12 15:20:36 -07:00
Ivan Kozlovic
3b8412049e [FIXED] Cluster's listener with IPv6
Trying to use IPv6 address for the cluster host would fail.
Also, there were some unclosed channels in case of accept loop
setup failures.

Resolves #323
2016-08-12 15:54:15 -06:00
Ivan Kozlovic
fc7d92a04a [FIXED] When server listens to any interface, return only global IPs
The server was returning all resolved IP addresses, including link
local addresses, which did not make sense for remote clients.

Resolves #321
2016-08-12 14:22:24 -06:00
Ivan Kozlovic
6f9d542393 Minor changes based on comments 2016-07-26 12:25:33 -06:00
Ivan Kozlovic
fda5bd7ac7 [ADDED] Server sends INFO with cluster URLs to clients with support
Clients that will be at the ClientProtoInfo protocol level (or above)
will now receive an asynchronous INFO protocol when the server
they connect to adds a *new* route. This means that when the cluster
adds a new server, all clients in the cluster should now be notified
of this new addition.
2016-07-26 10:55:55 -06:00
Derek Collison
7730fac9e2 Authorization enforcement and performance tweaks 2016-06-16 17:07:25 -07:00
Ivan Kozlovic
7bcb699903 Add /stacksz to monitoring
Allows to get the server's stacks from the monitoring interface.
2016-05-23 14:59:09 -06:00
Derek Collison
9e73c1db76 Enable listen address parsing for client, cluster and http, enforce http hosts as separate 2016-05-12 16:47:01 -07:00
Ivan Kozlovic
3691d14426 Fix missing capture of remoteID in removeClient
This needed to be captured under the client lock. Adding a test
that captured the races (when running enough times).
2016-04-22 18:06:38 -06:00
Ivan Kozlovic
3a999c1299 Add tracking of most go routines started by the server
Refactor the way client is initialized. We need to ensure that
clients are not added to the clients map and readLoop started if
the server is in the process of being shutdown otherwise there
is a chance that the server already gathered the list of connections
to close and this one would not be included, leaving a readLoop
running.
Same occurs for routes, with the complexity that the readLoop is
started well before the route connection is added to the server
routes' list. We need a temporary map that contains those connections
to be able to close them on server Shutdown.

Fixed some flapping tests.
2016-04-21 11:48:39 -06:00
Ivan Kozlovic
3aa09ecc01 Ensure Shutdown() waits for outstanding routes go routines
We need to make sure that when Shutdown() returns, routes go routines
that try to connect or reconnect have returned. Otherwise, this may
affect tests running one after the other (a server from one test
may connect to a server in the next test).
2016-04-21 11:48:39 -06:00
Derek Collison
5bea74c2ed Rename and move some things around 2016-04-21 09:33:26 -07:00
Derek Collison
b3388db53f Enable dynamic write buffers for client connections 2016-04-15 18:16:13 -07:00