Граф коммитов

64 Коммитов

Автор SHA1 Сообщение Дата
Joel Hendrix f631e69097
Add Null type for sending an AMQP null (#336)
* Add Null type for sending an AMQP null

* fix test names
2024-09-13 15:44:15 -07:00
Joel Hendrix 2dff4b36f8
Clean up some unused test variables (#321)
* Clean up some unused test variables

* change release date
2024-03-01 12:07:53 -08:00
Joel Hendrix e87e969fcd
Fix non-determinism in fake NetConn.Write (#302)
* Fix non-determinism in fake NetConn.Write

Serialize the responses to write so that they show up in their specified
order. This was responsible for some spurious test failures.
Consolidate creation of senders and receivers with test hooks.
Make sending and receiving of frames log level 0 to get the minimum
amount of logging that can be useful.

* check for context cancelled

* add unit test for Conn.getWriteTimeout and update changelog

* use delta comparison

* log error verbatim
2023-08-25 07:10:56 -07:00
Joel Hendrix e17dc337bc
Properly distinguish between input and output link handles (#293)
* Properly distinguish between input and output link handles

Per spec, peers can have different values for link handles.  When
sending a frame, its Handle is set to the output (our) handle.  When
receiving a frame, its Handle is set to the input (remote) handle.
Fixed session data structures to properly map an input handle to a link.
Renamed handle fields and supporting types to follow spec nomenclature.
Added a live test that reproduced the issue.

* set release date in changelog

* add debug logging message on link attach complete

* bump release date
2023-06-08 15:45:09 -07:00
Joel Hendrix b6b3ce0fc7
Robust handling of context expiration/cancellation (#276)
* Robust handling of context expiration/cancellation

If a context expires or is cancelled during session/link creation while
waiting for the ack, add the instance to a slice for later cleanup.
Removed force-closing of sessions/links.
Exhausting available session channels will return a *ConnError and close
the Conn.
Exhausting available link handles will return a *SessionError and close
the Session.

* add some additional tests

* add logging for abandoned sessions and links

* fix off-by-one error for default max links value
2023-04-18 12:59:38 -07:00
Joel Hendrix 3f5680733a
Honor context cancellation in Dial and NewConn (#273)
* Honor context cancellation in Dial and NewConn

Previously they only honored a deadline, now they handle both.
TLS dialer now calls DialContext().

* make linter happy

* switch to context.WithCancel just because
2023-04-03 13:32:37 -07:00
Joel Hendrix d6e714bcf7
Disable Session sending frames after end performative (#261)
* Disable Session sending frames after end performative

This is against the spec and results in the peer terminating the
connection.  Just ignore any outgoing frames.

* add debug logging when discarding frames
2023-03-17 15:49:07 -07:00
Joel Hendrix 48da0e91c3
Merge flowcontrol branch into main (#260)
* Replace messages channel with a queue (#244)

* Replace messages channel with a queue

The Receiver.messages channel placed an arbitrary restriction on the
amount of link credit that could be issued to a Receiver.  Once the
Receiver has been created, it can never be issued credit that exceeds
the size of the channel.
In addition, if the Receiver were to receive messages that exceeds the
size of the channel, due to flow control bugs or other, the writes to
the channel could block leading to hangs.
The channel has been replaced with a segmented FIFO queue.  While this
in theory could allow for unbounded growth, the reality is that the
total size can never be greater than that of the Session's incoming
window.

* use Ring from standard library

* switch to require.Same for pointer comparisons

fixed issue in last seg check and added another test

* refine and add another test

* size message queue to the incoming window

* add Holder[T] to abstract syncronized access

* Remove concept of "max credit" from Receivers (#251)

* Remove concept of "max credit" from Receivers

This exposed an implementation detail of how Receivers worked.  With the
removal of the Message channel, this is no longer required and never
really made sense anyways.
The MaxCredit and ManualCredits options have been consolidated into a
single Credit option.  This is used to set the total credit for a
Receiver in auto-flow mode, or to disable auto-flow.
Disposition batching needed some slight refactoring.  Now you can
directly specify the batch size instead of it being tied to link credit.
Received messages that are sender-settled now correctly count towards a
Receiver's credit and must be settled to reclaim it.

* fix linter

* back out double-buffering change for now

* refine threshold logic

* switch to mutex instead of channel for better perf

* add back fix to remove double buffering

* rename local var for clarity

* revert cosmetic change

* Replace incoming frame channels with queues (#253)

* Replace incoming frame channels with queues

The rx channel in Session and link has been replaced with a queue. This
ensures that parents enqueueing frames to their children is always a non
blocking operation and removes the need to "pump the mux".
Consolidated some link creation code into newLink().
Links echoing a flow frame now correctly include session info.
Reverted workaround for sending disposition frames from senders as we
can now send directly from muxHandleFrame.

* minor cleanup from review

* Remove configuration of session window (#257)

The values weren't actually honored which is ok per spec, so remove them
from the public surface area.
Cleaned up handling of sender link credit.  Since we don't use
availableCredit, it's been removed.

* Improve handling of sender-settled messages (#258)

Reclaim credit for sender-settled messages when Prefetch or Receive are
called.  This removes the need to explicitly settle the message.
2023-03-15 12:51:36 -07:00
Joel Hendrix c46f5ce9a7
Add Go 1.20 to CI (#238)
* Add Go 1.20 to CI

Update to latest golangci-lint.

* clean up linter issues
2023-02-09 10:29:27 -08:00
Joel Hendrix ccff88ac1f
Rename DetachError to LinkError (#230)
Detach has a specific meaning in AMQP and since we don't support link
detach/reattach the error type name is misleading.
Cleaned up any misused detach verbage.
2023-02-07 16:05:06 -08:00
Joel Hendrix 347d023335
Renamed Credit to MaxCredit (#229)
This accurately reflects its intended purpose.
2023-02-07 15:54:46 -08:00
Joel Hendrix d2322a6efe
Add option types for Send and Receive (#232)
To allow for future expansion.
2023-02-07 15:50:38 -08:00
Joel Hendrix 24ab09403d
Add context.Context param to Dial and NewConn (#222)
* Add context.Context param to Dial and NewConn

Removed ConnOptions.Timeout as it's no longer required.

* simplify code
2023-01-27 12:29:10 -08:00
Joel Hendrix 542954eb40
Enable at-most-once for senders (#213)
* Enable at-most-once for senders

When a sender's peer is in mode second, the disposition confirmation
must be sent through the session so that the in-flight disposition
tracker can be closed.

* remove potential for recursion

* add a couple code comments

* consolidate frame handling
2023-01-12 10:21:25 -08:00
Joel Hendrix bce5bd220e
Fix potential deadlock between senders and receivers (#210)
* Fix potential deadlock between senders and receivers

Receivers configured for ModeFirst weren't tracking unsettled messages.
As a result, their session would send them more messages than their link
credit would allow, causing the session mux to be blocked.
With the session mux blocked, senders within the same session were
unable to send messages.

* fix after rebasing

* fix auto-flow credit threshold
2023-01-11 13:24:19 -08:00
Joel Hendrix 5515441808
Remove conn.mux (#173)
* Remove conn.mux

conn.connReader() dispatches frames directly to sessions now.
Added conn.NextSession() and conn.DeleteSession() for deterministic
session management.
Channel numbers are now recycled immediately which prompted a fix for
TestSessionClose.
Fixed various tests to handle close frame (the error was being swallowed
before).
Tests that utilize testconn were silently failing due to a bug in
Conn.Read which has been fixed.

* simplify reader/writer error handling

* clean-up

* fix testconn.SetDeadline

* update changelog

* refine error check when closing net.Conn

fixed propagation of RemoteErr on close

* always reset idle read timeout before reading

* remove connReaderRun as it's no longer necessary

* consolidate calls to closeOnce.Do

* replace magic number with constant
2022-12-13 14:00:03 -08:00
Joel Hendrix 1d0e36752c
Refactor error types (#205)
* Refactor error types

The session and link sentinel error types have been removed.
Added SessionError type which allows more descriptive errors.
Fixed some error corner-cases to ensure they return DetachError.
Removed spurious error text on peer-initiated ending of a session.

* Enusre that peer-initiated end/detach is not ambiguous

Fixed doc comment for Conn

* add RemoteErr *Error field to error types and removed Unwrap()

removed synthetic *Error{} when peer doesn't provide an error

* log partial writes

* fix up docs and add examples

* fix copy/pasta

* more example clean-up
2022-11-21 19:38:58 -08:00
Joel Hendrix 0f9b2a92bb
Fix up const value names to match design guidelines (#197)
* Fix up const value names to match design guidelines

* Update ErrorCondition

* sort err const
2022-11-17 11:49:56 -08:00
Joel Hendrix 28a66ffb28
Update Go version to 1.18 (#203)
Allows usage of any instead of interface{}.
Removed imports of ioutil and replaced with equivalent packages.
Cleaned up README.md a little.
2022-11-16 17:53:58 -08:00
Joel Hendrix cfb062280f
Replace varadic config for Sender and Receiver with struct config (#165)
* Replace varadic config for Sender and Receiver with struct config

Added SenderOptions and ReceiverOptions types which replicates the
previous functional options.
Options that are specific to senders/receivers have been moved to their
respective options types.
Added Ptr() methods to SenderSettleMode and ReceiverSettleMode to
simplify setting these optional values.

* Removed error return from Prefetched

* clean-up
2022-06-28 16:27:10 -07:00
Joel Hendrix d0b8dfd515
Replace varadic config for Session with struct config (#161)
Added SessionOptions type which replicates the previous functional
options.
2022-06-27 16:24:13 -07:00
Joel Hendrix 69e69a86f1
Replace variadic config for conn with struct config (#160)
* Replace variadic config for conn with struct config

Added ConnOptions type which replicates the previous functional options
with the exception of ConnTLS which is redundant.
The SASL authentication mechanism is now singular instead of last one
wins.
Added SASLType for configuring SALS configuration.  The matching
configuration funcs have been renamed to match this type.

* fix linter issue

* update comment

* fix doc comments
2022-06-24 14:30:04 -07:00
Joel Hendrix b055e734dd
Add context parameter to methods that perform IO (#157)
Creating sessions, sending, and receiving messages all perform IO.
Removed context parameter from Prefetched() as it performs no IO.
2022-06-13 09:44:31 -07:00
Joel Hendrix ea44df592d
Various test clean-up (#152)
Added a bit more coverage for mode second integration tests.
Cleaned up linter noise for spurious usage of fmt.Sprintf.
Replaced assert with required for receiver tests.
2022-06-03 12:03:10 -07:00
Joel Hendrix ec2fd98be6
Update CI with latest versions of Go and linter (#145)
* Clean up tests to make linter happy

Bump Go version to 1.13 due to the use of signed shifts.

* update dependencies
2022-05-02 16:40:51 -07:00
Joel Hendrix b5919cead2
Return *ConnectionError when connection has faulted (#131)
* Return *ConnectionError when connection has faulted

Errors reading from/writing to the underlying net.Conn were being
propagated to the sender/receiver APIs, making them hard to identify.
Now, when the connection is no longer functional, a ConnectionError
instance is returned.  If the connection died due to a read/write error,
the ConnectionError will contain this information.
Removed ErrConnClosed as it's too simplistic and can't capture the
reason why the connection was closed.

* add comment about swallowed error

* remove comment
2022-03-04 12:28:45 -08:00
Joel Hendrix b64db1925b
Add unit tests for Session (#82)
* Add unit tests for Session

Added disambiguating text to more debug statements.
Fixed a race condition when concurrently creating sessions.
Added support for sender attach performative and encoding SASL frames.
Fixed a hang in session mux for malformed attach frame.
Added some clarifying comments to a few chunks of code.

* fix test after updating handle error count

* add comment and missing break
2021-10-13 13:03:52 -07:00
Joel Hendrix 917168828c
Add mocks package for unit testing (#77)
* Add mocks package for unit testing

This includes a mock net.Conn and various helper funcs for creating mock
response frames.
Moved frame parsing out of conn.go and into frames package so that the
mock infrastructure can use it.
Fixed a bug in link uncovered by new unit tests.
Rewrote receiver tests using the new framework.

* remove unused const

* remove stuttering

* little more renaming

* refine earlier fix for link Source

apply same fix for link Target
2021-10-04 16:56:20 -07:00
Joel Hendrix 760a290f7c
Move message disposition methods to Receiver (#69)
* Move message disposition methods to Receiver

Moved methods from Message to Receiver.
Removed Receiver.HandleMessage.
Fixed auto-accept in ModeFirst.
Check for closed link during blocking Receive.

* don't touch Message internals

* remove from unsettled map after ack of disposition
2021-09-30 17:06:12 -07:00
Joel Hendrix e23a615b05
Run integration tests against local broker (#54)
* Run integration tests against local broker

Uses the .NET Core AMQP broker for local E2E tests.
Removed tests that were specific to EH and SB.
Removed github workflow.

* run dotnet restore before run

* switch to .net 5 and update TFM

* fix runtime version

use non-standard port number to avoid collisions

* log broker address

* switch to loopback address

* start broker before tests

* invoke broker directly

* add execute bit to broker

* fix URI

* treat as env var

* test

* test

* test

* kill broker

* add headless switch
2021-09-03 15:51:07 -07:00
Joel Hendrix f44a71123a
Misc clean-up (#49)
* Misc clean-up

Removed some dead code.
Fixed minor linter issues.
Updated CI to latest versions of Go.

* fix 1.17 version string

* update build constraints for 1.17

* add basic codeowners file
2021-09-02 10:50:57 -07:00
Stéphane Erbrech 825d6e69a4
fix: emit amqp Flow on message handling completion (#20)
* use pending messages to decide on flow control

* add detailed debug logging

* remove unecessary parenthesis

* add tests that shows receive failure and HandleMessage success

* lock on len(pendingMessages)

* add message.Ignore() to allow consumer to explicitely control the amqp message pump

* add integration tests

* mod tidy

* remove dependency on amqp-common

* re-add the build tag that got yanked in rebase

* rename pending to unsettled
2021-02-11 19:44:32 -08:00
Stéphane Erbrech a84bc5b401
test: un-comment integration tests (#21)
* re-enable integration tests for servicebus

* re-add build tag

Co-authored-by: Joel Hendrix <jhendrix@microsoft.com>
2021-02-11 16:47:18 -08:00
Joel Hendrix 289bca0a6b
Fixes for initial release (#1)
* Fixes for initial release

Fixed references to new package path.
Removed dependencies on Azure SDK for now; this required disabling the
integration tests as they depend on it.
Added go.mod and go.sum files.
Added back content removed from README.md file.

* add initial devops CI pipeline
2019-12-11 16:10:19 -08:00
Kale Blankenship ffafbe49c0 Fix settlement handling and add Message.SendSettled
* Message.SendSettled allows sending messages settled when
  LinkSenderSettle is ModeMixed.
2019-08-22 11:09:33 -07:00
Kale Blankenship de9a8ae33e Validate received transfers adhere to the spec 2019-07-15 18:01:42 -07:00
Kale Blankenship ca53772c6c Return server link creation error at time of Sender/Receiver creation.
Server errors during link creation are reported by sending an Attach
without a source or target and immediately sending a follow up Detach.
Check for this situation and wait for the Detach so the error can be
returned to the user immediately.
2019-06-18 19:09:14 -07:00
Kale Blankenship 25244797b1 Fix TestIntegrationClose tests
LinkTargetAddress was incorrectly being used with Session.NewReceiver
instead of LinkSourceAddress.

Some Close calls were being done in seperate goroutines.
2019-01-09 18:28:48 -08:00
Han van der Veen 39ddcebef1 Implement shared consumer #138 2018-10-23 07:37:44 -07:00
Kale Blankenship 61c7441786 Default batching to false.
Batching has been enabled by default since the early days of this
library. In retrospect I think this was a mistake. I believe most users
would expect messages to be acknowledged immediately when calling
`Message.Accept()` (evidenced in #127). Requiring explicit opt-in
should lessen the risk of bugs due to the batching behavior.
2018-10-20 09:30:22 -07:00
Lawrence Gripper 271d6282f5 Add deliverytag to Message type (#126) 2018-09-07 07:42:29 -07:00
Kale Blankenship 5dba116cc9 Ensure buffered messages are received after link closed.
Resolves #110
2018-07-21 15:19:06 -07:00
Kale Blankenship 404f5d173b Wait for response disposition when Receiver w/ rcv-settle-mode second.
Fixed some potential bugs due to receiver and sender dispostions
being treated them same in Session.mux.
2018-06-17 17:25:47 -07:00
Kale Blankenship 0438881ea9 Fix receiver flow control.
Link should not send additional credits when there are queued
transfers/messages waiting to be read via `Receiver.Receive`. Message
decoding is moved into the `link.mux` goroutine so that the link can
know how many messages are queued by checking the `link.messages`
channel length. If the channel fills the link is effectively paused.
The receiver can indicate it can process additional message and unblock
the link my sending on `link.receiverReady`.

When additional credits are issued, `link.linkCredit` must be updated
before receiving any additional messages to ensure the sender and
receiver stay in sync.

Similarly, `link.deliveryCount` should not be arbitrarily changed based
on a flow frame received from the sender.
2018-06-17 13:24:28 -07:00
Kale Blankenship 73065a4669 Reuse handle and channel numbers
* Track numbers in a lazily initialized bitmap.
* Both will now use the lowest free number.
* Added SessionMaxLinks option mirroring ConnMaxSessions.
* Attempting to create a new link when max has been reached will return
  an error.
* Fixed error causing fields set to zero to be encoded as null even
  though the field default is not zero.

Resolves #68
Resolves #76
2018-04-15 08:24:31 -07:00
Kale Blankenship 2f33ce8002 Make Sender.Send safe for concurrent use. 2018-04-14 14:33:43 -07:00
Kale Blankenship ee6eb7ef6e Add support for graceful close timeouts via contect.Context
* `Close()` is now `Close(context.Context)` for sessions and links.
* `Client.Close` does not take a context as it does not currently
  block.
* Added `-count=1` to integration tests to prevent caching on Go1.10+.
2018-04-11 15:20:21 -07:00
Kale Blankenship 7ff561750e Fix link-credit to track messages instead of transfers 2018-03-26 17:06:20 -07:00
David Justice 6723ae740f add test for send fail 2018-03-26 16:42:56 -07:00
Kale Blankenship 65e9423ece
Prevent delivery-id from being incremented for multi-transfer messages (#55)
Fixes #54
2018-03-24 15:46:02 -07:00