Skip to content

NOT FOR MERGE: Demonstrate failures with heartbeats. - #60

Closed
andrewbelcher wants to merge 1 commit into
stomp-php:masterfrom
andrewbelcher:heartbeat
Closed

NOT FOR MERGE: Demonstrate failures with heartbeats.#60
andrewbelcher wants to merge 1 commit into
stomp-php:masterfrom
andrewbelcher:heartbeat

Conversation

@andrewbelcher

Copy link
Copy Markdown
Contributor

No description provided.

@michael-mader

Copy link
Copy Markdown

any progress on this?

@staabm

staabm commented May 23, 2017

Copy link
Copy Markdown
Member

What is this PR about? What should it achieve?

@michael-mader

michael-mader commented May 23, 2017

Copy link
Copy Markdown

I thought it addresses some connection issues, but probably it doesn't.
I ran into issues causing activemq to show the client as not connected but the php script is running fine. So maybe there is a problem reading data from socket. But I can't reproduce it...
Anyway this is more an issue than a comment to a PR.

I will create an issue for that if I got more information.

@andrewbelcher

Copy link
Copy Markdown
Contributor Author

This is a demonstration that heartbeats cause it to think that there is data to read, and so get perpetually stuck gobbling data, rather than returning that there is no data to read.

@michael-mader

Copy link
Copy Markdown

I ran into a similar issue with heartbeats disabled. There seems to be some PHP bugs which lead to problems when using stream_select and fread.

https://bugs.php.net/bug.php?id=52602
https://bugs.php.net/bug.php?id=51056

@jmglsn

jmglsn commented May 23, 2017

Copy link
Copy Markdown
Member

@andrewbelcher sorry for the late response and thank you for the PR.

That's right for the moment we don't support heartbeats. If we want to support heartbeats we must first think about different problems that we get with the beats. The main issue is timing. We would need to assure that the logic that is added on top on the client / around the read() or / send() is executed within a specific time - otherwise our code has no chance to check for a missed beat / sending a beat in time.

I think we could just add another layer which would take care about reading and sending heartbeats. If we want to integrate it into the state machine we could add new states for this. But it should not be part of the default machine, as most clients don't take care about timing. (Correct me if you have seen other things out there.)

When timing is something that is important, please consider to use https://github.com/reactphp. Here you get the power to declare that something must be executed within a specified interval. I'm not sure id the stomp extension for react is ready... see #69.

@Fender123 so ActiveMQ shows the client as disconnected while the client is still running and processing data? What version is in use?

@andrewbelcher

Copy link
Copy Markdown
Contributor Author

Yes, so I wasn't trying to get heartbeat support, but rather demonstrate that if a server was sending a heartbeat it caused us to think there is a frame to read and get stuck gobbling data. See the linked issue where I was getting long periods with no feedback. I'm not certain heartbeats were the issue it was just one theory.

@michael-mader

Copy link
Copy Markdown

@jmglsn let me explain the setting to you.
There is a Stomp client listening to a DurableSubscription. Those clients are listed in http://activemq.host/admin/subscribers.jsp. At some point (can't tell exactly when) the client is displayed as offline and therefore doesn't receive messages anymore. But the longrunning PHP script is still running, that means there is no ConnectionException or other exception. The Stomp Client thinks that the connection is still open and working but activemq thinks the client has gone away. I can't tell if the connection is still open or actually closed. I suspect it is related to those PHP Bugs caused by using stream_select and fread.

stomp-php: 4.2.1
activemq: 5.14.5

@jmglsn

jmglsn commented May 24, 2017

Copy link
Copy Markdown
Member

@andrewbelcher ok, I'll create a feature branch for this, so that we're able to receive them and make some checks on top on in - maybe this helps as start for tracing the actual issue.

@Fender123, what ACK mode do you use? Can you try to configure it to client individual?

@jmglsn
jmglsn self-requested a review May 24, 2017 05:56
@michael-mader

Copy link
Copy Markdown

@jmglsn I'm using auto ACK. I can test client individual ACK in the next days

@jmglsn

jmglsn commented May 25, 2017

Copy link
Copy Markdown
Member

Just added a feature branch with a draft for sending heartbeats to the server.

// It's important that the read timeout is lower than the beat interval.
$this->Stomp->setHeartbeat(0,500); // at least after 0.5 seconds we will let the server know that we're alive
$this->Stomp->getConnection()->setReadTimeout(0, 250000); // after 0.25 seconds a read operation must timeout
// we add a beat emitter to the observers of our connection
$this->Stomp->getConnection()->getObserver()->addObserver(new Emitter($this->Stomp->getConnection()));

Now the Emitter will send beats when you do passive operations (e.x. read) on the connection. I tested with activem, but as I mentioned, it's only a draft :)

jmglsn added a commit that referenced this pull request May 29, 2017
- add observer based heartbeat emitter, which must be added to the connection if outgoing heartbeats are wanted
- allow to use heartbeats when connection is reopened by server
- fix older test cases to be more precise and fix preconditions
jmglsn added a commit that referenced this pull request Jun 11, 2017
* add a basic heartbeat emitter that allows to send heartbeats (#60)

- add observer based heartbeat emitter, which must be added to the connection if outgoing heartbeats are wanted
- allow to use heartbeats when connection is reopened by server
@jmglsn

jmglsn commented Jun 11, 2017

Copy link
Copy Markdown
Member

Included in our latest release https://github.com/stomp-php/stomp-php/releases/tag/4.2.2

Thank you!

@jmglsn jmglsn closed this Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants