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

Transient publishing for #164 #166

Merged
merged 8 commits into from
Nov 28, 2018

Conversation

mattheworiordan
Copy link
Member

This PR adds support for transient publishing as defined in the spec atL:

I thought it would be useful to additionally see what's involved in support transient publishing from the proposed Client#publish method defined at ably/specification#64. Interested to hear your views on this.

error = Ably::Exceptions::ChannelInactive.new("Cannot publish messages on a channel in state #{state}")
return Ably::Util::SafeDeferrable.new_and_fail_immediately(logger, error)
end

if !connection.can_publish_messages?
error = Ably::Exceptions::MessageQueueingDisabled.new("Message cannot be published. Client is configured to disallow queueing of messages and connection is currently #{connection.state}")
error = Ably::Exceptions::MessageQueueingDisabled.new("Message cannot be published. Client is not allowed to queue of messages when connection is in state #{connection.state}")
Copy link
Member

Choose a reason for hiding this comment

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

"to queue of messages" -> "to queue messages"

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, good spot.

if messages.length > Realtime::Connection::MAX_PROTOCOL_MESSAGE_BATCH_SIZE
error = Ably::Exceptions::InvalidRequest.new("It is not possible to publish more than #{Realtime::Connection::MAX_PROTOCOL_MESSAGE_BATCH_SIZE} messages with a single publish request.")
return Ably::Util::SafeDeferrable.new_and_fail_immediately(logger, error)
end
Copy link
Member

Choose a reason for hiding this comment

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

Where'd this MAX_PROTOCOL_MESSAGE_BATCH_SIZE requirement come from? Don't remember any discussion on this, and it's not in the spec afaict

Copy link
Member Author

Choose a reason for hiding this comment

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

See fd267e6. I mentioned in that commit that this limit existed before, so I have kept it as it was. @paddybyers I believe we have a max ProtocolMessage size, but do we have / want any limit on how many messages can exist within a single ProtocolMessage?

@@ -111,16 +111,12 @@ def fail_messages_awaiting_ack(error, options = {})
end
end

# When a channel becomes detached, suspended or failed,
# When a channel becomes suspended or failed,
# all queued messages should be failed immediately as we don't queue in
# any of those states
def fail_queued_messages(error)
error = Ably::Exceptions::MessageDeliveryFailed.new("Queued messages on channel '#{channel.name}' in state '#{channel.state}' will never be delivered") unless error
fail_messages_in_queue connection.__outgoing_message_queue__, error
Copy link
Member

Choose a reason for hiding this comment

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

fail_messages_in_queue connection.__outgoing_message_queue__, error

Not something you added in this pr, but: am I misunderstanding something, or does this fail every message in the connection queue if any channel becomes suspended or failed? That's not right, surely

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that is not correct, see https://github.com/ably/ably-ruby/pull/166/files/f7a524e00e64a47cf5c9d974dbcf621f5b82307a#diff-b8c5e1edac0c00c8db3f3e6ebcc8e749R125, only the messages for that channel. However, based on what we agree on ably/docs#470, I'll most likely need to modify this...

@@ -102,7 +102,11 @@ def dispatch_protocol_message(*args)
if channel.attached?
channel.manager.duplicate_attached_received protocol_message
else
channel.transition_state_machine :attached, reason: protocol_message.error, resumed: protocol_message.has_channel_resumed_flag?, protocol_message: protocol_message
if channel.failed?
logger.warn "Ably::Realtime::Client::IncomingMessageDispatcher - Received an ATTACHED protocol message for FAILED channel #{channel.name}. Ignoring ATTACHED message"
Copy link
Member

Choose a reason for hiding this comment

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

Is there a spec for this? Having the client deliberately ignore what the server is telling it the channel state is is a bit of a break from our usual model (of the server deciding and telling the client), no?

Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't a change of behaviour. This was raising an exception before because a channel is not allowed to transition from failed directly to attached. See

transition :from => :failed, :to => [:attaching]
. I perhaps should investigate more under what conditions this has happened (I saw this exception bubble up in one of the tests), but I'd prefer to create a separate issue as it's not related to this PR, this change just made the library handle the problem better.

@mattheworiordan
Copy link
Member Author

ably/docs#470 is merged, so I need to implement this change before this is ready for review again.

@mattheworiordan mattheworiordan force-pushed the transient-publishing-issue-164 branch from fdf2065 to 841ac62 Compare August 3, 2018 17:10
@mattheworiordan mattheworiordan mentioned this pull request Nov 13, 2018
@mattheworiordan mattheworiordan force-pushed the transient-publishing-issue-164 branch from 841ac62 to a139e37 Compare November 13, 2018 23:49
@mattheworiordan mattheworiordan changed the base branch from master to v1-1-release November 13, 2018 23:49
@mattheworiordan mattheworiordan force-pushed the transient-publishing-issue-164 branch from a139e37 to 1dd646f Compare November 28, 2018 00:04
@mattheworiordan mattheworiordan merged commit 1dd646f into v1-1-release Nov 28, 2018
@mattheworiordan mattheworiordan deleted the transient-publishing-issue-164 branch November 28, 2018 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants