Skip to content

[Messenger] Fix BatchHandlerTrait::flush() ignoring force parameter #61293

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

Closed
wants to merge 1 commit into from

Conversation

wazum
Copy link
Contributor

@wazum wazum commented Jul 31, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #61292
License MIT

The flush() method was ignoring the $force parameter and always flushing when jobs existed, violating the BatchHandlerInterface contract which states flushing "can be skipped if not" forced.

This caused inefficient batching behavior where flush(false) calls during worker idle periods would prematurely process partial batches instead of waiting for the batch size threshold to be reached.

What it does

Fixes BatchHandlerTrait::flush(bool $force) to respect the $force parameter:

  • Before: flush(false) and flush(true) behaved identically - always flushed when jobs existed
  • After: flush(false) only flushes when shouldFlush() returns true (batch size reached)

Example

$handler = new MyBatchHandler(); // batch size: 3

// Add 1 message (batch not full)
$handler->handle($message, $ack);

// Before fix: Would flush the 1 message
// After fix: Does not flush (waits for batch to fill)
$handler->flush(false);

// Always flushes (unchanged behavior)
$handler->flush(true);

Impact

This fixes the Worker's flush behavior during idle periods:

  • Worker::run() calls flush(false) when no messages are handled
  • Previously this would flush partial batches, defeating batching efficiency
  • Now respects the intended batching behavior per the interface contract

@carsonbot carsonbot added this to the 6.4 milestone Jul 31, 2025
@wazum wazum force-pushed the bugfix/batch-handler-flush-false branch from 348a1f7 to ab157f5 Compare July 31, 2025 21:56
The flush() method was ignoring the $force parameter and always flushing when jobs existed, violating the BatchHandlerInterface contract which states flushing "can be skipped if not" forced.

Resolves symfony#61292
@wazum wazum force-pushed the bugfix/batch-handler-flush-false branch from ab157f5 to e1ad595 Compare July 31, 2025 22:05
@OskarStark OskarStark changed the title [Messenger] Fix BatchHandlerTrait::flush() ignoring force parameter [Messenger] Fix BatchHandlerTrait::flush() ignoring force parameter Aug 1, 2025
@wazum
Copy link
Contributor Author

wazum commented Aug 1, 2025

This is still not the right solution and leads to other problems. I'll close this for now.

@wazum wazum closed this Aug 1, 2025
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy