Commit Graph

122 Commits

Author SHA1 Message Date
Derek Collison
684c9f473e User JWT support
Signed-off-by: Derek Collison <derek@nats.io>
2018-11-23 16:48:08 -08:00
Ivan Kozlovic
bb1816c573 Add space trimming when looking for key and update test
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-11-04 08:37:49 -07:00
Ivan Kozlovic
9462c580fa Added test for NkeyOptionFromSeed
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-11-02 20:23:22 -06:00
Derek Collison
9da7a9a1ef Added nkey seed file helper and updated examples
Signed-off-by: Derek Collison <derek@nats.io>
2018-11-02 16:57:22 -07:00
Derek Collison
990b4574ed Nkey support
Signed-off-by: Derek Collison <derek@nats.io>
2018-10-26 09:23:03 -05:00
Ivan Kozlovic
ea8e897968 [IMPROVED] URL parsing allowing to skip scheme and default port
With this change, you could pass URL "host" and it will translate
to "nats://host:4222". Also, if attempting to connect to a server
that requires TLS, the Secure option will be automatically turned
on and an attempt to make a secure connection will be made.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-08-13 17:47:01 -06:00
Derek Collison
442868de47 Added drain mode for subscribers
Signed-off-by: Derek Collison <derek@nats.io>
2018-08-06 15:11:29 -07:00
Derek Collison
9f825b9453 Add support for NoEcho option
Signed-off-by: Derek Collison <derek@nats.io>
2018-07-24 17:14:10 -07:00
Ivan Kozlovic
35b4f0c894 [FIXED] Close() release resources immediately
When a connection is closed very quickly after being created, there
was a race condition that could lead to the connection object still
being referenced (and therefore holding resources) until the first
ping interval elapsed.
This was because the pinger was created in spinGoRoutines() which
was itself created as a go routine. When the Close() call was made,
the ping timer may still be nil (therefore no way to stop it), but
then created in the go routine (which caused the reference to the
connection object). By default, it means that the connection object
would be held for 30 seconds.
Doing connect/close in a tight loop would show the process size
growing.

This PR refactors where we create the pinger and the use of the
wait group. There had been a change in a past to attempt to fix
a WaitGroup panic. I believe this approach is more stable. We do
create the pinger and bump the wait group in processConnectInit,
under connection lock. The doReconnect() go routine waits for
this wait group on entry and then on iterations where a failure
occurs after we know we have started the go routines.
In case of failures in the reconect loop, some state has also been
properly reset (namely the connection's buffered writer).

Resolves #368

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-06-12 09:36:11 -06:00
Ivan Kozlovic
65cf3c3628 Remove duplicate test and inline creation of handler
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-06-12 09:02:44 -06:00
Ivan Kozlovic
f9649c3633 [FIXED] Dispatching of asynchronous callbacks
This is a follow up on #365. Working on another issue and running
tests, I still had a race on the original ach or a panic on send
to close channel.

Move from a channel to a linked list with dedicated lock.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
2018-06-11 18:51:55 -06:00
Clement Rey
2f1c4e556e TestConnAsyncCBDeadlock now limits the number of goroutines 2018-05-18 17:24:19 +02:00
Clement Rey
6f19798679 Moved TestConnAsyncCBDeadlock to main package 2018-05-18 16:47:34 +02:00
Ivan Kozlovic
5d21257b56 Use tag[1:] directly in string comparison 2018-03-23 09:07:51 -06:00
Ivan Kozlovic
a543a276c0 Added test ensuring version matches tag on new release
Doing a new release by pushing a tag will allow a test to run and
verify that the library version matches the given tag.

```
git tag -a vX.Y.Z -m "Release vX.Y.Z"
git push --tags
```

If the test fails, then we would delete the newly created tag,
fix the version string and recreate the tag.
2018-03-22 20:15:04 -06:00
Derek Collison
2f0e8883ae CNCF, move to Apache 2 2018-03-17 13:36:48 -07:00
Ivan Kozlovic
82fff71b0e [IMPROVED] Server pool is updated based on server notifications
The server pool was only growing when new servers were discovered.
Now, the client library updates its server pool based on server's
INFO protocols (true for server 1.0.6+).
The DiscoveredServersCB is still invoked only when new servers
are added (as in never seen as opposed to added back after leaving
the cluster).

The code should work ok with older servers but will take advantage
of changes in the server (https://github.com/nats-io/gnatsd/pull/626)
2018-02-27 16:32:15 -07:00
Ivan Markin
12ef716a17 Add GetDefaultOptions() function that produces new default Options
on every call. Deprecate DefaultOptions.
2017-07-29 17:41:45 +00:00
Tyler Treat
18d330ce42 Allow handling of authorization errors from the server
Once we introduce config reload support for users, it's possible for a
user to be disconnected due to a change in credentials. Before the user
is disconnected, the server sends an authorization error. We should
allow the user to handle this error in the async error callback.
2017-06-09 17:21:58 -05:00
Ivan Kozlovic
c3e6ea9f5f [FIXED] Do not shuffle entire pool when adding URL from INFO
When connecting to a server, the received INFO may contain an array
of URLs. The current code was adding those and then shuffeling the
entire pool (if NoRandomize is false). This is wrong since the
connect (and reconnect) loop would then potentially skip never
tried servers and try again servers that had just failed.
2017-01-26 16:44:14 -07:00
Ivan Kozlovic
43dd8139c1 Fix staticcheck reported issues
The tool is started with the "-ignore" flag to ignore warning SA2002
which corresponds to invoking t.Fatalf (and the like) in a go routine.
Calling t.Fatalf in a go routine may produce a race condition.
The rationale for ignoring this warning is that if a test executes
the t.Fatalf() line it is that we have a problem either with test
or code that should be fixed.
2016-11-15 13:00:33 -07:00
Colin Sullivan
fc3a10245d Rename to DiscoveredServers 2016-10-19 17:25:51 -06:00
Colin Sullivan
1f3b8c4c05 Merge branch 'master' into add-servers-api 2016-09-08 16:27:55 -06:00
Ivan Kozlovic
a6d3e81814 [FIXED] If Options.Url is set, try it first on initial connect
The recent change in processing of INFO protocol changed that
behavior by shuffling the entire pool. Now ensure that if Opts.Url
is set, it is first in the array.
2016-09-06 18:31:26 -06:00
Colin Sullivan
fe06f51d8e Trim out user credentials and add ImplicitServers API 2016-08-30 16:14:11 -06:00
Colin Sullivan
e74d9e7eb7 Use the length of the returned servers rather than the pool. 2016-08-22 16:51:54 -06:00
Colin Sullivan
8069c881dc [ADDED] Add Conn.Servers API
* Returns a string array of all known servers including those updated by the async INFO protocol.
2016-08-22 11:28:57 -06:00
Ivan Kozlovic
a73f86b517 Fixed INFO split parsing
Added test for split buffer when processing INFO protocol
2016-08-01 13:19:30 -06:00
Ivan Kozlovic
6db5372cae [ADDED] Support for processing of asynchronous INFO protocols
This would be used in conjunction with server's PR #314.
The client may receive INFO protocols with a field containing
a possible array of URLs that correspond to server addresses in
the full mesh cluster that clients can connect to.
The server pool is updated with these URLs.
3 new Options and 2 new Options setters have been introduced to
manage username/password and/or tokens when dealing with these
bare URLs.

cc /derekcollison
2016-08-01 12:27:39 -06:00
Ivan Kozlovic
2e583da420 Create helper function
- In sendConnect(), checks if it is an -ERR, if so, normalize error, otherwise return protocol error.
- Change ErrAuthorization text to end with 'violation' to match server
- Add test for normalizeErr
2016-02-04 19:06:55 -07:00
Ivan Kozlovic
9123ce65dd Fix processing of error coming from server.
- Trim quotes and convert to lower case before processing error
- Fix parse of error test to just check parser state
- Add two tests to check for stale connection and other error
- Check expected authentication failure error message on connect
2016-02-04 13:52:06 -07:00
Ivan Kozlovic
b5cb0e5e92 Fix nc.Flush() on connection close + much more code coverage.
- If nc.Flush[Timeout]() was waiting for a response and the connection would close, nc.Flush() would return without error. This is not appropriate. It will now return ErrConnectionClosed.
- Adding/Updating several tests for more code coverage.
2016-02-01 18:48:28 -07:00
Derek Collison
81eaf95b22 Merge pull request #145 from nats-io/fix_stale_connection
Fix "Stale Connection" error check.
2016-01-29 12:27:02 -08:00
Ivan Kozlovic
5a74e0ceab Change error back to lower case, convert incoming error to lower before
check.
2016-01-29 11:15:51 -07:00
Ivan Kozlovic
e546ba40b2 Modify test for more coverage. 2016-01-28 19:00:38 -07:00
Ivan Kozlovic
21da13b93d Fix "Stale Connection" error.
The case of the error message was changed to all lower case in the
client. The server is using mixed case. This would cause the check to
fail, resulting in connection close, instead of possibly trying to
reconnect.
2016-01-28 18:51:38 -07:00
Ivan Kozlovic
9a0abce686 Fix parser bug introduced in #139
- Used from 'scratch' field
- Improve test to check for msg content
2016-01-28 13:46:29 -07:00
Ivan Kozlovic
6de46bda97 Merge branch 'optimize_large_msgs' of github.com:nats-io/nats into optimize_large_msgs 2016-01-27 13:07:53 -07:00
Ivan Kozlovic
464936bd00 Update test for a bit more coverage. 2016-01-27 13:05:27 -07:00
Ivan Kozlovic
53d4d04111 Add parser test for split messages.
Note: it seems that the parser code coverage in the client is not that
great. Since the code is common in part with the server, we know that
this code is tested, but wonder if we need to duplicate tests existing
in the server.
2016-01-27 13:05:27 -07:00
Ivan Kozlovic
68053d80f9 Fix parser to check for missing sid.
Adding tests for code coverage, I discovered that we would not check for
missing sid (sid would be -1 due to parseInt64). I believe sid is
mandatory.
2016-01-27 11:48:59 -07:00
Ivan Kozlovic
8d1dd084fd Update test for a bit more coverage. 2016-01-27 09:07:13 -07:00
Ivan Kozlovic
21f3557115 Add parser test for split messages.
Note: it seems that the parser code coverage in the client is not that
great. Since the code is common in part with the server, we know that
this code is tested, but wonder if we need to duplicate tests existing
in the server.
2016-01-25 18:19:19 -07:00
Ivan Kozlovic
a4cf1de03c Fix test for parallel run.
Specify different ports for package tests.
2016-01-25 11:57:03 -07:00
Derek Collison
a2a2033ed3 Fix for race 2016-01-20 04:30:04 -07:00
Derek Collison
1b497d9155 Allow comma separated url arrays as args to Connect 2016-01-16 09:47:29 -08:00
Derek Collison
e52a3ae745 Moved tests over, reconnect and test cleanup 2015-09-16 22:22:25 -07:00
Derek Collison
95e093ed42 Fixed race conditions 2015-08-06 00:18:32 -07:00
Derek Collison
8e765a3c21 Increased coverage 2014-12-14 21:07:55 -08:00
Derek Collison
0ed4d6c27d Up timeout to help slow travis 2014-09-10 16:57:58 -07:00