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

Only call fwrite() if select() said the fd is ready. #1132

Merged

Conversation

Sthing
Copy link
Contributor

@Sthing Sthing commented Oct 18, 2023

The current code calls fwrite() even when select_write() returns 0, ie when the write is expected to fail with EAGAIN (Resource temporarily unavailable). This happens if the TCP transmit buffer is full.
In real life I have seen select() return 0 and fwrite() succeeds anyway - I guess some room became available between the two calls.
But at one point fwrite() will fail with EAGAIN - and then an AMQPIOException occurs.

With the proposed changes fwrite() will not result in EAGAIN. Instead the result is an AMQPTimeoutException if the fd is still blocking after $this->write_timeout.

(See #1131 for a question about how the timeout should be calculated).

I don't know if this change should include any new tests.

I have used rabbitmqctl set_vm_memory_high_watermark 0on the RabbitMQ server to force the EAGAIN error when testing this issue.

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (73d6fe1) 74.01% compared to head (e5e52a9) 73.71%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1132      +/-   ##
============================================
- Coverage     74.01%   73.71%   -0.31%     
- Complexity     1035     1037       +2     
============================================
  Files            39       39              
  Lines          3125     3127       +2     
============================================
- Hits           2313     2305       -8     
- Misses          812      822      +10     
Files Coverage Δ
PhpAmqpLib/Wire/IO/SocketIO.php 80.66% <100.00%> (+0.12%) ⬆️
PhpAmqpLib/Wire/IO/StreamIO.php 71.96% <100.00%> (+0.13%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ramunasd
Copy link
Member

Thanks, this indeed was missed when select_write() was introduced.

@ramunasd ramunasd added this to the 3.6.0 milestone Oct 22, 2023
@ramunasd ramunasd merged commit abee57c into php-amqplib:master Oct 22, 2023
11 checks passed
@Sthing Sthing deleted the only-write-if-select-succeeded branch October 23, 2023 06:23
@lukebakken
Copy link
Collaborator

Thank you @Sthing and @ramunasd !

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.

None yet

3 participants