Skip to content

fix broken connection handling - #107

Merged
jmglsn merged 4 commits into
stomp-php:masterfrom
fin-sn-de:bugfix/104-fix-broken-connection-handling
Mar 19, 2018
Merged

fix broken connection handling#107
jmglsn merged 4 commits into
stomp-php:masterfrom
fin-sn-de:bugfix/104-fix-broken-connection-handling

Conversation

@jmglsn

@jmglsn jmglsn commented Feb 27, 2018

Copy link
Copy Markdown
Member

This enables non-blocking stream operations and replaces stream_get_line with fread. As the the previous code failed to recognize that the broker connection was dropped.

This solves #104.

@jmglsn
jmglsn requested review from aelrazek and staabm February 27, 2018 20:01

@staabm staabm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Need a more in deep review tomorrow

Comment thread src/Network/Connection.php Outdated
}
$data = $stompFrame->__toString();
if (!@fwrite($this->connection, $data, strlen($data))) {
if (@fwrite($this->connection, $data, strlen($data)) !== strlen($data)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IIRC this is not a good idea on non-blocking streams.
We either need to buffer/remember what was not yet written, or do a retry in case we have no buffer

@jmglsn

jmglsn commented Feb 27, 2018

Copy link
Copy Markdown
Member Author
  • Check how we handle fwrite on the non blocking stream
  • Check timing for time_nanosleep

This also adds a write timeout to the Connection.
Comment thread src/Network/Connection.php Outdated
if (@fwrite($this->connection, $data, strlen($data)) !== strlen($data)) {
throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
}
$this->writeData($stompFrame->__toString(), $this->writeTimeout);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would pass the Frame into writeData and to the toString() stuff inside the method

{
$offset = 0;
$size = strlen($data);
$lastByteTime = microtime(true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't this be inside the loop?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would like to avoid that it's not timing out in case we don't have a successful write at all. So I set the initial value as first timeout challenge.

@jmglsn
jmglsn merged commit 7822745 into stomp-php:master Mar 19, 2018
@jmglsn
jmglsn deleted the bugfix/104-fix-broken-connection-handling branch March 19, 2018 19:21
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.

2 participants