Skip to content

Conversation

@AmadulHaque
Copy link
Contributor

Fix: DivisionByZeroError when Thread Count is 0

Problem

The application was crashing with a DivisionByZeroError when the configured number of threads was set to 0.
This occurred during the calculation of file batch sizes for parallel processing.

Root Cause

The $this->threads value was being directly taken from configuration without validation.
When it was 0, the calculation:

ceil($totalFiles / $this->threads)

resulted in division by zero.

Solution

Added validation in the constructor to ensure the thread count is always at least 1:

$this->threads = max(1, $this->configuration->getNumberOfThreads());

Impact

Prevents application crashes when thread configuration is set to 0

Ensures reliable parallel processing with a minimum of 1 thread

Maintains backward compatibility with existing configurations

Testing

The fix ensures that even with threads: 0 in configuration, the application will run successfully with a single thread instead of crashing.

👉 Do you want me to also make a **changelog-style version** (like `CHANGELOG.md` format) or keep it as a **detailed fix report**? 
Set threads to at least 1 when configuration returns 0 to avoid division by zero error in file processing batch calculation.
@nunomaduro nunomaduro merged commit 1f020e5 into nunomaduro:master Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants