Skip to content

fix: prevent fwrite be stuck by large streams - #111

Merged
jmglsn merged 1 commit into
stomp-php:masterfrom
ganeko:prevent_large_messages_writing_timeout
Oct 11, 2018
Merged

fix: prevent fwrite be stuck by large streams#111
jmglsn merged 1 commit into
stomp-php:masterfrom
ganeko:prevent_large_messages_writing_timeout

Conversation

@ganeko

@ganeko ganeko commented Oct 3, 2018

Copy link
Copy Markdown
Contributor

Under some systems, writing entire large message will cause process block. In this case, fwrite returns 0 and method throws Was not possible to write frame! Write operation timed out. exception.

Splitting message into smaller chunks will prevent this behavior.

Warning returned by actual writeData method:

PHP Warning:  fwrite(): SSL operation failed with code 1. OpenSSL Error messages:
error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry in /vendor/stomp-php/stomp-php/src/Network/Connection.php on line 390

Tested under:

  • PHP 5.6.38
  • Stomp PHP 4.4.1
  • Amazon MQ (Active MQ 5.15.6)

@jmglsn
jmglsn merged commit 696b540 into stomp-php:master Oct 11, 2018
@jmglsn

jmglsn commented Oct 11, 2018

Copy link
Copy Markdown
Member

@ganeko thank your for the fix, it's included in 4.4.2.

@ganeko

ganeko commented Oct 11, 2018

Copy link
Copy Markdown
Contributor Author

Great!. Thank you @jmglsn !

@ganeko
ganeko deleted the prevent_large_messages_writing_timeout branch October 11, 2018 08:41
@gabrielspiteri-highlight

Copy link
Copy Markdown

@ganeko could you elaborate on the fix please?

@ganeko

ganeko commented Jan 22, 2019

Copy link
Copy Markdown
Contributor Author

Hi @gabrielspiteri-highlight ,

Since 4.4.3 version you are able to set, on execution time, a custom connection's read/write max bytes, based on your custom stack.

You can check this PR, #113

@gabrielspiteri-highlight

Copy link
Copy Markdown

@ganeko I see but I don't understand how does this address the problem when fread() returns an empty string?

@ganeko

ganeko commented Jan 22, 2019

Copy link
Copy Markdown
Contributor Author

@gabrielspiteri-highlight fread can return empty string because OpenSSL issue, not directly related to this library. If you let this library throw a exception, you will see the exception from OpenSSL. General speaking, you can get a SSL_ERROR_WANT_WRITE or SSL_ERROR_WANT_READ error.

Only for debug purpose, you can remove @ from https://github.com/stomp-php/stomp-php/blob/master/src/Network/Connection.php#L471 and see what OpenSSL is saying.

@gabrielspiteri-highlight

Copy link
Copy Markdown

@ganeko Removing the @ suppression ... code still moves along and simple returns an empty string. Any further info about which OpenSSL issue you refer to?

@ganeko

ganeko commented Jan 22, 2019

Copy link
Copy Markdown
Contributor Author

@gabrielspiteri-highlight I don't know your current stack but the problem you report comes from OpenSSL or related protocol. Maybe reducing write length will help you.

I debugged my problem logging fread warning as I said.

@gabrielspiteri-highlight

Copy link
Copy Markdown

@ganeko in my case messages are written to the queue by another system ... you mean it could be possible that the other system is not writing these messages properly?

@ganeko

ganeko commented Jan 22, 2019

Copy link
Copy Markdown
Contributor Author

@gabrielspiteri-highlight this will be one reason, yes.

@gabrielspiteri-highlight

Copy link
Copy Markdown

@ganeko i believe I managed to work around this with using version 4.3.1 for stomp-php/stomp-php

@jmglsn

jmglsn commented Feb 2, 2019

Copy link
Copy Markdown
Member

@gabrielspiteri-highlight as already mentioned, please feel free to open a new issue including more details about the problem that you face, this will simplify the support or possible bugfixing. Rolling back to an old version is not a good idea in a long term scenario.

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