Commit Graph

574 Commits

Author SHA1 Message Date
Derek Collison
99fed910f0 Improvements to large numbers of JetStream R1 consumers per stream.
1. We were holding open FDs longer than we should for consumers causing issues with open FD limits. We now do not hold them open and cap updates a bit better.

2. When doing a stream delete, consumer delete was repeating alot of work that was not necessary, causing longer delays. This has been optimized a bit, still more improvements to be made.

3. We cover all JS under a single export, but that was also trapping GetNext for pull based consumers, and since this was a no-op (is handled at user account level) we were creating alot of garbage service import responses and reverse map entries that had to be garbage collected. We have a fix in to avoind this but still looking for a better one.

4. Still had some lingering references to all exports vs single JS export.

Signed-off-by: Derek Collison <derek@nats.io>
2021-06-29 05:45:55 -07:00
Ivan Kozlovic
1d3cddfa7c [CHANGED] Reduce print for an account subs limit to every 2 sec
We could make it for all limits by having a map of error types
instead of applying just to max subs.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-06-22 11:00:41 -06:00
Matthias Hanel
83389db226 [fixed] hanging leaf node connection when account can't be found (#2267)
* [fixed] hanging leaf node connection when account can't be found

as a result of the issue, the leaf node connection never got created,
even after the account can be found.

Also tracing account id and name (when available)

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-06-10 11:55:16 -04:00
Derek Collison
e238512285 Handling of rewrites for subjects to a globally routed subject was not properly handling c.pa.deliver or reply rewrite.
Signed-off-by: Derek Collison <derek@nats.io>
2021-06-09 15:34:47 -07:00
Ivan Kozlovic
308be7ecd3 [FIXED] MQTT: panic when using import/export
The issue was that the subscription created for the MQTT client
was resulting in creation of a shadow subscription which did not
have the mqtt specific object attached, which would cause the
panic when accessing it in the sub's icb.

After that, it was discovered that the wrong subject was passed
to deliverMsg(), so fixed that too so that the icb callback gets
the proper transformed subject.

Resolves #2265

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-06-08 15:03:12 -06:00
Matthias Hanel
b1dee292e6 [changed] pinned certs to check the server connected to as well (#2247)
* [changed] pinned certs to check the server connected to as well

on reload clients with removed pinned certs will be disconnected.
The check happens only on tls handshake now.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-05-24 17:28:32 -04:00
Derek Collison
a52697170c Fix for corrupting a message when extending an existing header.
We had a report of corrupt message payloads when going across leafnodes between streams that were sourced from one another.
We were incorrectly using the underlying buffer when a header already existed.

Signed-off-by: Derek Collison <derek@nats.io>
2021-05-23 11:28:48 -07:00
Derek Collison
bd01f202af Under double import scenarios we could map to the wrong subject.
Signed-off-by: Derek Collison <derek@nats.io>
2021-05-19 05:59:24 -07:00
Derek Collison
908b5ec304 Fix for #2205
When a response was needed from a leafnode cluster back to a hub, we had rules to disallow.
That rule was a bit dated and since we have cluster origin for leafnode clusters and that
is checked before the message is actually sent we could remove the old rule.

Signed-off-by: Derek Collison <derek@nats.io>
2021-05-12 06:49:11 -07:00
R.I.Pienaar
5e06e5e232 Export the clientOpts structure
This structure is used in ClientAuthentication, an interface
designed to let 3rd parties extend the authentication mechanisms
of the server

In order to allow those 3rd parties to create unit tests, mocks etc
we need to export this structure so it's accessible externally

Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-05-07 15:51:31 +02:00
Derek Collison
0bd92e85da Add in formal support for multiple JetStream domains across leafnodes.
This CL adds in support for multiple JetStream domains using mapped subjects.
Mapping subjects aligns well with the JetStream context APIPrefix in clients.

Signed-off-by: Derek Collison <derek@nats.io>
2021-05-06 18:45:27 -06:00
Ivan Kozlovic
2881e4a1f0 [FIXED] MQTT fixes and improvements
Some issues that have been fixed would manifest by timeouts on
connect, unexpected memory usage on high publish message rate.

Some details:
- Replies were not always GW routed properly because we were looking
at the wrong connection's rsubs
- GW routed replies would not be found because they were tracked
in the subscription's client object, which may not be the same used
to send the reply
- Increased the mqtt timeout to wait for JS replies since in some
tests it was sometimes taking more than the original 2 seconds
- Incoming gateway messages destined for an MQTT internal subscription
may have been rejected as a no interest if the account had service imports
- Don't use time.After(), instead create explicit timer so it can
be stopped when not timing out.
- Unnecessary copy of a slice since we were converting to a string anyway.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-05-04 20:48:14 -06:00
Derek Collison
ba31bb6165 When detecting a jetStream domain that is extended to a leafnode or leafnode cluster
we want to auto-suppress JetStream traffic on normal accounts.

We also now track remote accounts so that client info headers can be remapped.

Signed-off-by: Derek Collison <derek@nats.io>
2021-04-30 15:23:12 -07:00
R.I.Pienaar
c7caa576f5 Merge pull request #2165 from ripienaar/custom_auth_username
allow custom authenticators to set a username
2021-04-30 14:37:50 +02:00
R.I.Pienaar
683887ca97 allow custom authenticators to set a username
Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-04-30 14:22:19 +02:00
Ivan Kozlovic
53a14eb5d1 Merge pull request #2163 from nats-io/msg_loop
[FIXED] Message loop with cluster, leaf nodes and queue subs
2021-04-29 10:02:17 -06:00
Derek Collison
96072d66f0 Internal JetStream callbacks for message delivery across GWs could lose responses.
For internal callbacks we can not rely on the GW routed reply tracking
since internal clients can change who receives vs sends response.

Signed-off-by: Derek Collison <derek@nats.io>
2021-04-29 07:27:44 -07:00
Ivan Kozlovic
01ff1b76c1 Fixed comments
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-28 19:32:16 -06:00
Ivan Kozlovic
e2e3de9977 [FIXED] Message loop with cluster, leaf nodes and queue subs
In a setup with a cluster of servers to which 2 different leaf nodes
attach to, and queue subs are attached to one of the leaf, if the
leaf server is restarted and reconnects to another server in the
cluster, there was a risk for an infinite message loop between
some servers in the "hub" cluster.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-28 17:11:51 -06:00
Ivan Kozlovic
8d4102c404 Merge pull request #2093 from shkim-will/flush_client_only
[CHANGED] Flush in place only if producer and consumer are client connections
2021-04-23 09:18:56 -06:00
William
084b0a29c8 apply review - rephrase 2021-04-21 12:31:55 +09:00
Ivan Kozlovic
32f1a58b09 Move cas in prunePubPermsCache() itself and clear with atomic.Store
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-20 21:18:13 -06:00
Ivan Kozlovic
1014041be3 [FIXED] Possible panic due to concurrent access to unlocked map
This could happen when a leafnode has permissions set and another
connection (client, etc..) is about to assign a message to the
leafnode while the leafnode itself is receiving messages and they
both check permissions at the same time.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-20 21:18:13 -06:00
William
30303d1250 add 'flushClientsWithCheck' to prevent block in readLoop 2021-04-20 15:07:02 +09:00
Matthias Hanel
b3e355c263 [fixed] sub ref count issue across leaf node connections
This was caused by not sending subs across leaf node connections in some
cases but sending unsub in all cases. This imbalance caused
subscriptions to go away too soon. (ref count was off)

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-04-15 20:13:57 -04:00
Derek Collison
35bf0e8ce5 Merge pull request #2122 from nats-io/cleanup_tests
Cleanup some tests + GetTLSConnectionState() race fix
2021-04-15 13:57:51 -07:00
Ivan Kozlovic
6e1205b660 Cleanup some tests + GetTLSConnectionState() race fix
Missing defers

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-15 11:37:43 -06:00
Ivan Kozlovic
56d0d9ec87 Do not propagate service import interest across GW and ROUTES
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-04-15 11:34:36 -06:00
Derek Collison
6788c757d1 Merge pull request #2108 from nats-io/lnjs
Improve JS when a leafnode cluster extends and shares a system account.
2021-04-12 17:24:13 -07:00
Matthias Hanel
9486722e96 [fixing] subscription issue when subscribing to a super set of deny_import
If the subscription was foo. > but the server also had an import deny of foo.bar
It was legal to send the subscription. But the other server was unaware
of the restriction and sent the message anyway. The check of the
incoming message did not happen.

Fixing by ignoring messages the server is not supposed to receive.
And exchange deny_import so that the non soliciting leaf node knows to not
send these messages in the first place.

NB. merging of deny_ export/import with perms from INFO happens in processLeafnodeInfo

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-04-12 20:09:55 -04:00
Derek Collison
755ef74855 When a cluser of leafnodes connects to a cluster or supercluster hub and they share the system account make the leafnode servers observers.
Signed-off-by: Derek Collison <derek@nats.io>
2021-04-12 17:00:55 -07:00
Matthias Hanel
f7a772f097 Ensure that leafNodeFinishConnectProcess is only executed once.
incorporate review comments

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-04-09 16:53:06 -04:00
Matthias Hanel
5d1f36dd17 [Fixed] leaf node subscription permission negotiation.
On connect all subscription where sent by the soliciting leaf node.
If creds contains sub deny permissions, the leaf node would be
disconnected.
This waits for the permissions to be exchanged and checks permissions
before sending subscriptions.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-04-09 16:53:06 -04:00
William
e845592644 Try to flush in place, if producer and consumer are client. 2021-04-09 18:03:41 +09:00
R.I.Pienaar
f2d1a173db expose the connection kind to CustomClientAuthentication
Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-04-08 18:33:55 +02:00
Ivan Kozlovic
c7f8296a85 Merge pull request #2065 from alexpantyukhin/extract_server_update
extract_server_update
2021-04-08 09:01:51 -06:00
alexpantyukhin
e16bebb8df extract update remote subscription. 2021-04-08 16:37:12 +04:00
alexpantyukhin
84884a93b5 put typestring to map and add tests 2021-04-05 22:03:14 +04:00
Matthias Hanel
b154c3d957 [Fixed] remote subscription leak for leafnodes caused by auto unsubscribe
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-04-02 17:38:57 -04:00
Ivan Kozlovic
b17f38e356 [FIXED] Websocket: do not generate empty frames + LN corruption
- It was possible that when the server was sending frames to a
webbrowser, it would send empty frames. While technically not wrong,
prevent that from happening.
- Not copying enqueued buffers could cause corruption with LN+WS.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-03-26 16:17:46 -06:00
R.I.Pienaar
d6e63cb683 improve log line when account registration fails
Signed-off-by: R.I.Pienaar <rip@devco.net>
2021-03-18 12:19:23 +01:00
Ivan Kozlovic
ccec4a6ab1 Fixed consumer idle hearbeats and JS route/GWs unsubscribes
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-03-09 12:08:47 -07:00
Derek Collison
e70e46ea4a Updates based on PR feedback
Signed-off-by: Derek Collison <derek@nats.io>
2021-03-04 16:16:28 -08:00
Derek Collison
bfb8e3432e Move RAFT comms off internal sendq.
Move route and gateway msgs our of fast path for inbound stream msgs.

Signed-off-by: Derek Collison <derek@nats.io>
2021-03-04 14:45:34 -08:00
Ivan Kozlovic
e7e756034a Switch Gateway JS accounts to interest-only mode + some other fixes
- Fixed the close of a TLS connection which starting Go 1.16
set the deadline to 5 seconds.

- Fixed an issue with setHeader that was causing these error messages
```
=== RUN   TestServiceImportReplyMatchCycleMultiHops
nats: message could not decode headers on connection [4] for subscription on "foo"
--- PASS: TestServiceImportReplyMatchCycleMultiHops (0.04s)
```

- Fixed names of tests in norace_test.go since they must start with
TestNoRace in order to make sure that we execute them in Travis:
```
go test -v -run=TestNoRace --failfast -p=1 ./...
```

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2021-03-03 19:15:28 -07:00
Matthias Hanel
25ef6b0f0d Merge pull request #1952 from nats-io/goland-lint
Fixed linter issues
2021-03-02 21:43:04 -05:00
Matthias Hanel
c50ee2a1c6 [Changed] all times exposed will be computed in UTC (#1943)
This also applies to times that end up in that json.
Where applicable moved time.Now() to where it is used.
Moved calls to .UTC() to where time is created it that time is converted
later anyway.

Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-02 21:37:42 -05:00
Matthias Hanel
4f2db7d187 Fixed linter issues
Signed-off-by: Matthias Hanel <mh@synadia.com>
2021-03-02 20:21:44 -05:00
Derek Collison
49cd38c064 Enable cross account behaviors for mirrors and sources.
Signed-off-by: Derek Collison <derek@nats.io>
2021-03-02 06:36:57 -08:00
Derek Collison
44b08c538a Pass deliver, don't remap
Signed-off-by: Derek Collison <derek@nats.io>
2021-02-25 17:42:03 -08:00