Commit Graph

2085 Commits

Author SHA1 Message Date
Derek Collison
4e6d600ecc Also make sure account works after reload
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-30 16:18:36 -08:00
Derek Collison
7e27042e6e Fix for #1736
When a system account was configured and not the default when we did a reload we would lose the JetStream service exports.

Signed-off-by: Derek Collison <derek@nats.io>
2020-11-30 16:11:50 -08:00
Ivan Kozlovic
77aead807c Send LS- without origin to route
When cluster origin code was added, a server may send LS+ with
an origin cluster name in the protocol. Parsing code from a ROUTER
connection was adjusted to understand this LS+ protocol.
However, the server was also sending an LS- with origin but the
parsing code was not able to understand that. When the unsub was
for a queue subscription, this would cause the parser to error out
and close the route connection.

This PR sends an LS- without the origin in this case (so that tracing
makes sense in term of LS+/LS- sent to a route). The receiving side
then traces appropriate LS- but processes as a normal RS-.

Resolves #1751

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-30 13:31:32 -07:00
Derek Collison
4532447908 Remove limitation on ackall for filtered consumers
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-28 07:18:17 -08:00
R.I.Pienaar
5e5b2e4dfd ensure the stream originating a pub error is reported
Signed-off-by: R.I.Pienaar <rip@devco.net>
2020-11-27 12:24:41 +01:00
Ivan Kozlovic
cceab9a46f System account was not properly tracking GW routed replies
In some cases, the reply of a request message is prefixed when
going over a gateway so that if it comes back to a different
server than when the request originates, it can be routed back.

For system accounts, this routed reply subject was not tracked
so the server would reply to the inbox and may reach a server
that had not yet processed (through the route) the interest
on that inbox. If the reply came with the GW routed info, that
server would know to route it to the original server.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-25 15:51:12 -07:00
Derek Collison
5d8b9eb608 Merge pull request #1748 from nats-io/fs_consumer_bug
Fixed bug restoring consumer state
2020-11-25 14:17:02 -08:00
Derek Collison
f69b199e0f Fixed bug restoring consumer state.
We were not properly restoring our state for consumers and we also had a bug where we would not properly encode and write redelivered state.

Signed-off-by: Derek Collison <derek@nats.io>
2020-11-25 13:31:46 -08:00
Derek Collison
bcf295dd51 Changed dcount -> dc
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-25 13:30:29 -08:00
Derek Collison
de0c992ca6 Merge pull request #1747 from nats-io/jsupdates
JetStream changes.
2020-11-25 08:07:48 -08:00
Derek Collison
954f5a9093 Flattened filters for stream names API
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-25 07:46:56 -08:00
Derek Collison
44a1373f89 JetStream changes.
Made several changes based on feedback.

1. Made PubAckResponse only optionally include an ApiError and not force an API type.
2. Allow FilterSubject to be set on a consumer config and cleared if it matches the only stream subject.
3. Remove LookupStream by subject, and add in filters for stream names API.

Signed-off-by: Derek Collison <derek@nats.io>
2020-11-25 06:50:25 -08:00
Phil Pennock
bc6c433142 FreeBSD fixes: %cpu scale; no-cgo for amd64
It would be convenient if we did not need to use cgo to compile for
FreeBSD for common architectures, allowing builds to be generated in
Linux CI flows.

The sysctl interface uses offsets which can vary by build architecture,
so doing this in the general case without cgo is not realistic.  But we
can front-load the C work to get the offsets for a given architecture,
then use encoding/binary at run-time.

While doing this, I saw that the existing FreeBSD code was
mis-calculating `%cpu` by converting the `fixpt_t` scaled int straight
to a double without dividing by the scaling factor, so we also fix for
all other architectures by introducing a division by `FSCALE`.

The offsets-emitting code is in `freebsd.txt`, with the filename chosen
to keep the Go toolchain from picking it up and trying to compile.

The result is unsafe-free cgo-free builds for FreeBSD/amd64.
2020-11-24 23:04:50 -05:00
Ivan Kozlovic
406dc7ee56 Fixed data race on leafnode check for remote cluster
A newly introduced test (TestLeafNodeTwoRemotesBindToSameAccount)
had a server creating two remotes to the same server/account.
This test quite often show the data race:
```
go test -race -v -run=TestLeafNodeTwoRemotesBindToSameAccount ./server -count 100 --failfast
=== RUN   TestLeafNodeTwoRemotesBindToSameAccount
==================
WARNING: DATA RACE
Write at 0x00c000168790 by goroutine 34:
  github.com/nats-io/nats-server/v2/server.(*client).processLeafNodeConnect()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:1177 +0x314
  github.com/nats-io/nats-server/v2/server.(*client).processConnect()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/client.go:1719 +0x9e4
  github.com/nats-io/nats-server/v2/server.(*client).parse()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/parser.go:870 +0xf88
  github.com/nats-io/nats-server/v2/server.(*client).readLoop()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/client.go:1052 +0x7a5
  github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode.func4()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:872 +0x52

Previous read at 0x00c000168790 by goroutine 32:
  github.com/nats-io/nats-server/v2/server.(*client).remoteCluster()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:1203 +0x42d
  github.com/nats-io/nats-server/v2/server.(*Server).updateLeafNodes()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:1375 +0x2cf
  github.com/nats-io/nats-server/v2/server.(*client).processLeafSub()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:1619 +0x858
  github.com/nats-io/nats-server/v2/server.(*client).parse()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/parser.go:624 +0x5031
  github.com/nats-io/nats-server/v2/server.(*client).readLoop()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/client.go:1052 +0x7a5
  github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode.func4()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:872 +0x52

Goroutine 34 (running) created at:
  github.com/nats-io/nats-server/v2/server.(*Server).startGoRoutine()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/server.go:2627 +0xc7
  github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:872 +0xf7a
  github.com/nats-io/nats-server/v2/server.(*Server).startLeafNodeAcceptLoop.func1()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:474 +0x5e
  github.com/nats-io/nats-server/v2/server.(*Server).acceptConnections.func1()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/server.go:1784 +0x57

Goroutine 32 (running) created at:
  github.com/nats-io/nats-server/v2/server.(*Server).startGoRoutine()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/server.go:2627 +0xc7
  github.com/nats-io/nats-server/v2/server.(*Server).createLeafNode()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:872 +0xf7a
  github.com/nats-io/nats-server/v2/server.(*Server).startLeafNodeAcceptLoop.func1()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/leafnode.go:474 +0x5e
  github.com/nats-io/nats-server/v2/server.(*Server).acceptConnections.func1()
      /Users/ivan/dev/go/src/github.com/nats-io/nats-server/server/server.go:1784 +0x57
==================
    testing.go:965: race detected during execution of test
--- FAIL: TestLeafNodeTwoRemotesBindToSameAccount (0.05s)
```

This is because as soon as a LEAF is registered with the account, it is available
in the account's lleafs map, even before the CONNECT for this connectio is processed.
If another LEAF connection is processing a LSUB, the code goes over all leaf connections
for the account and may find the new connection that is in the process of connecting.
The check accesses c.leaf.remoteCluster unlocked which is also set unlocked during
the CONNECT. The fix is to have the set and check on that particular location using
the client's lock.

Ideally I believe that the connection should not have been in the account's lleafs,
or at least not used until the CONNECT for this leaf connection is fully processed.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-24 15:42:30 -07:00
Ivan Kozlovic
88475014ef [FIXED] Split LMSG across routes
If a LeafNode message is sent across a route, and the message
does not fit in the buffer, the parser would incorrectly process
the "pub args" as if it was a ROUTED message, not a LEAF message.
This caused clonePubArg() to return an error that would cause
the parser to end with a protocol violation.

Keep track that we are processing an LMSG so that we can pass
that information to clonePubArg() and do proper parsing in split
scenario.

Resolves #1743

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-24 14:55:50 -07:00
Ivan Kozlovic
120b031ffd Merge pull request #1739 from nats-io/leaf-warning
[Added] account name checks for leaf nodes in operator mode
2020-11-24 12:35:31 -07:00
Matthias Hanel
b0461e3921 Fixed comment
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-24 12:47:41 -05:00
Matthias Hanel
a0dc9ea3e3 Reducing complexity of lookup
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-24 12:31:44 -05:00
Ivan Kozlovic
637717a9f3 Merge pull request #1738 from nats-io/fix_1730
[FIXED] LeafNode reject duplicate remote
2020-11-24 09:22:11 -07:00
Matthias Hanel
a8390b7432 Incorporating comments and moving code
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-23 23:27:44 -05:00
Matthias Hanel
e2e69b6daf [Added] account name checks for leaf nodes in operator mode
Rules out implausible ones.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-23 15:38:41 -05:00
Ivan Kozlovic
f155c75da7 [FIXED] LeafNode reject duplicate remote
There was a test to prevent an errorneous loop detection when a
remote would reconnect (due to a stale connection) while the accepting
side did not detect the bad connection yet.

However, this test was racy because the test was done prior to add
the connections to the map.

In the case of a misconfiguration where the remote creates 2 different
remote connections that end-up binding to the same account in the
accepting side, then it was possible that this would not be detected.
And when it was, the remote side would be unaware since the disconnect/
reconnect attempts would not show up if not running in debug mode.

This change makes sure that the detection is no longer racy and returns
an error to the remote so at least the log/console of the remote will
show the "duplicate connection" error messages.

Resolves #1730

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-23 13:28:18 -07:00
Derek Collison
c0bc788c6d Merge pull request #1735 from nats-io/ehdrs
Stream publish changes
2020-11-23 09:44:37 -08:00
Derek Collison
18108be374 Merge pull request #1731 from nats-io/cycle
[FIXED] Detect service import cycles.
2020-11-23 09:43:51 -08:00
Derek Collison
2e7b47f692 Merge pull request #1733 from nats-io/jsimport
Allow complete $JS.API to be imported from another account.
2020-11-23 07:35:24 -08:00
Derek Collison
39e96984ac Force a copy of the PubAck normal response
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-23 07:10:09 -08:00
Phil Pennock
7c1f50d920 Unbreak FreeBSD compilation (syscall.Statfs_t) (#1734)
The types of fields in syscall.Statfs_t varies between platforms.
fs.Bavail is uint64 on Linux and int64 on FreeBSD.  This is the opposite way
around to fs.Bsize.

For now, just coerce the Bavail to be uint64.

If the VFS layer might return -1 for one or the other of these then these casts
will be problematic and we'll need more safeguards.
2020-11-22 20:00:37 -05:00
Derek Collison
afa5cae58c Formalized PubAckResponse
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-22 16:31:37 -08:00
Derek Collison
a50f96461b Allow to check for last sequence and last msgid for conditional publish
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-22 15:12:00 -08:00
Derek Collison
bcb777150a Fix race
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-22 10:24:32 -08:00
Derek Collison
b528b1f74e Allow complete $JS.API to be imported from another account.
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-21 16:54:58 -08:00
Derek Collison
2e3c226729 Fix for service import cycles
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-21 13:13:08 -08:00
Ivan Kozlovic
4d51a41dfd Merge pull request #1727 from nats-io/tls-verify-and-impliict-allow
[ADDED] verify_cert_and_check_known_urls to tie subject alt name to url in cfg
2020-11-20 15:10:01 -07:00
Matthias Hanel
8fd1b66f66 Renaming to verify_cert_and_check_known_urls
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 16:56:44 -05:00
Derek Collison
beda0c397a Merge pull request #1729 from nats-io/js_export
Enable JetStream streams and consumer access to be exported
2020-11-20 11:28:44 -08:00
Matthias Hanel
eda80ff7b5 changing the option name verify_and_implicit_allow to verify_and_accept_known_urls
This follows the suggestion by phil. I added the and to be similar to verify_and_map.
I fixed a minor issue where the implicit verify could be overwriting an
explicitly configured one.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 14:27:24 -05:00
Matthias Hanel
f24aec4af7 Incorporating comments and fixed an issue where code was not invoked
had to change failing tests to use insecure as to not fail due to the
outgoing connection being not trusted.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 13:57:34 -05:00
Matthias Hanel
74642e024e [Added] verify_and_implicit_allow to tie subject alt name to url in cfg
Only works for gateways and routes. When true the subject alt DNS name
must match one url in the corresponding configuration

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-20 13:57:34 -05:00
Derek Collison
a1c1ead39d Enable JetStream streams and consumer access to be exported to another account
Signed-off-by: Derek Collison <derek@nats.io>
2020-11-20 10:17:16 -08:00
Matthias Hanel
1229bed9fa [Adding] ability to reference $SYS in leaf node config
only do so if $SYS is the system account

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-19 22:32:42 -05:00
Ivan Kozlovic
55b0f8d855 [FIXED] LeafNode: duplicate queue messages in complex routing setup
Suppose a cluster of 2 servers, let's call them leaf1 and leaf2.
These servers are routed and have a leaf connection to another
server, let's call it srv1.
They share the same cluster name.

If a queue subscriber runs on srv1 and a queue subscriber on the
same subject/group name runs on leaf1, if a requestor runs on
leaf2, the request should reach only one of the 2 queue subs.

The defect was that sometimes both queue subs would receive the
message.

The added test checks that only one reply is ever received and
that the local "leaf" cluster is preferred.

Resolves #1722

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2020-11-18 11:23:08 -07:00
Phil Pennock
bfd388e8b4 Bump beta version (.33) (#1724) 2020-11-18 10:49:42 -05:00
Ivan Kozlovic
16d7d032e1 Merge pull request #1719 from nats-io/fetch-acc-nkeys-only
Only fetch account jwt if the name is a proper public account key
2020-11-17 17:46:14 -07:00
Matthias Hanel
2c2a6e45fe Incorporating comment and making fetchAccount private
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-17 19:26:34 -05:00
Derek Collison
28d8a4be9c Merge pull request #1721 from nats-io/fsfix2
Fix for not properly recovering first sequence number on recovery.
2020-11-17 15:22:02 -08:00
Derek Collison
d358aaddf6 Fixes for filestore not remember first sequence when all messages deleted.
Thsi fixed a few minor bugs as well as the one where we did not remember our sequence numbers.

Signed-off-by: Derek Collison <derek@nats.io>
2020-11-17 15:04:57 -08:00
Matthias Hanel
3b4da21e07 Rename reject_unknown to reject_unknown_cluster
this is supposed to make it clearer what is being rejected

Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-17 17:54:45 -05:00
Matthias Hanel
f69dc5cfd6 Only fetch account jwt if the name is a proper public account key
Signed-off-by: Matthias Hanel <mh@synadia.com>
2020-11-17 17:18:47 -05:00
Derek Collison
68416d291b Merge pull request #1717 from nats-io/ackReply
Optimize ackReply parsing
2020-11-17 11:44:34 -08:00
Ivan Kozlovic
86ea8b9b45 Merge pull request #1718 from AdamKorcz/master
Updated fuzzer
2020-11-17 12:02:35 -07:00