Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(session): add support for multiple sessions per client #332

Merged
merged 1 commit into from
Jan 24, 2018

Conversation

princjef
Copy link
Collaborator

@princjef princjef commented Sep 7, 2017

Addresses #331 by adding the ability to create multiple sessions on the same client/connection and providing policy options for reestablishing the session on end. This feature set is designed to better align the capabilities of amqp10 with the session pattern supported by Azure Service Bus and bring the retry logic inline with what is used for reattach and reconnect.

Features

  • Add createSession() in AMQPClient to create user sessions
    • Support custom policy overrides
  • Allow an optional session to be passed in on createSender(), createSenderStream(), createReceiver(), createReceiverStream()
  • Create the default session associated with the client only when needed
  • restart policy option for reestablishing the session after it is ended

Tests

  • createSession()
  • Optional session parameter for createSender(), createSenderStream(), createReceiver(), createReceiverStream()
  • Creating default client session on demand
  • Session policy - restart

Please take a look and let me know what you think of the change. I'm open to changing the design/approach if people have other thoughts.


This change is Reviewable

@princjef princjef force-pushed the multi-session branch 6 times, most recently from 72715a8 to 6dfc2bb Compare September 7, 2017 17:16
@princjef
Copy link
Collaborator Author

princjef commented Sep 7, 2017

I also pulled in the change from #330 for now so that I can get useful information from the Travis CI build. That change looks good to me and I think it's worth merging in before this goes in.

@princjef princjef force-pushed the multi-session branch 2 times, most recently from 9d4210f to 94f9f91 Compare September 8, 2017 02:16
@princjef
Copy link
Collaborator Author

princjef commented Sep 8, 2017

Review status: 0 of 10 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


lib/policies/policy.js, line 127 at r1 (raw file):

      enableSessionFlowControl: true,
      closeOnLinkError: false,
      reattach: null

I'm not wild about calling this reattach, since the concept of attach/detach applies to links, not sessions. The equivalent for the session terminology would be rebegin or remap, but neither really feels right to me. Thoughts?


Comments from Reviewable

@princjef
Copy link
Collaborator Author

I decided to remove the endOnLinkDetach policy from the session because it's not a part of the spec and was causing more problems than it was solving. The other changes have stood up well to my testing though

@princjef princjef force-pushed the multi-session branch 3 times, most recently from b57de35 to 75e080f Compare September 28, 2017 03:34
@amarzavery amarzavery closed this Jan 22, 2018
@amarzavery amarzavery reopened this Jan 22, 2018
resolve();
});

self._session.begin(self._session.policy || self.policy.session);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._session.policy || self.policy.session [](start = 30, length = 43)

if these 2 are the same, no problem. if the existing session doesn't have a policy object, apply the configured one. i get that part - but what if self._session.policy is set to something that is incompatible with self.policy.session (which i assume is the desirable policy) ? should these objects be merged instead ? or why keep the existing policy object at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright the tricky part here is that the policy isn't applied at creation time, but when begin() is called. therefore, we need to provide the policy each time we start the session again (or it gets cleared out).

for the session created with the client, the policy is never specified directly by the user so i'm fine with doing a merge if we want. the user-created sessions are trickier because they can be specified independently and should supersede that of the client. in those cases we really only want to apply the client's policy if we don't have one (which should never happen but i've been caught by those assumptions too many times to not put in the check).

sound reasonable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha I see. the philosophy of policies as i understand it though is that they are merged and what is passed around are policy overrides - so starting with the client policy and then merging/overriding with the session policy would feel like the natural thing to do. but i defer to your judgement.


In reply to: 163131314 [](ancestors = 163131314)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's reasonable to do the merge on the built-in one (this line). the user one is weird because the begin() here is a hidden operation. the policy for the session is specified separately so i don't want to override it if it's already there. i'll add a comment to that one


if (promises.length > 0) {
Promise.all(promises).then(function() {
self.emit('connected');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.emit('connected'); [](start = 10, length = 23)

unrelated but puzzling nonetheless to me: why would the "connected" state of the client be attached to sessions rather than connection or links?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this one is an artifact of how the Promise-based design works. it's trying to make sure things are in a usable state when the promise returns. since the session is baked into the connection by the library, that means both the connection and the session have to be ready. i considered making it lazy, but didn't know that i'd be able to get away with it without some subtle breaking changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually i did make it lazy. the problem is reconnect because the session is already there

@@ -22,7 +22,7 @@ var test = {
connect: { options: { containerId: 'test' } },
senderLink: { attach: { name: 'sender' } },
receiverLink: { attach: { name: 'receiver' } }
}, DefaultPolicy)
}, DefaultPolicy),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, [](start = 19, length = 1)

typo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably had something else and took it out. good catch

@pierreca
Copy link
Collaborator

reestablish? the spec talks about establishing and ending sessions


In reply to: 328216141 [](ancestors = 328216141)

Copy link
Collaborator

@pierreca pierreca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@princjef
Copy link
Collaborator Author

ah i like that. reestablish sounds better to me than restart


Comments from Reviewable

@princjef
Copy link
Collaborator Author

lib/amqp_client.js, line 176 at r2 (raw file):

Previously, princjef (Jeff Principe) wrote…

i think it's reasonable to do the merge on the built-in one (this line). the user one is weird because the begin() here is a hidden operation. the policy for the session is specified separately so i don't want to override it if it's already there. i'll add a comment to that one

Done.


Comments from Reviewable

@princjef
Copy link
Collaborator Author

test/unit/test_session.js, line 25 at r2 (raw file):

Previously, princjef (Jeff Principe) wrote…

probably had something else and took it out. good catch

Done.


Comments from Reviewable

@pierreca pierreca merged commit da6fe5a into noodlefrenzy:master Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants