Repository: actix/actix-net (language: rust)

Issue:
manually setting workers(0) will actually spin 0 thread
Just a little thing, I noticed. at server building when you set .workers(0) then it will actually spin 0 threads and no request goes though. My expectation was that by setting 0, it would load whatever the default value for workers would be. Is it a bug or desired behavior? If bug, I'd be glad to send a PR.
right now with: actix-web "3.0.0-beta.1"


Discussion / hints:
I can't think of a use case for calling it with zero workers. Might be worth a warn log but I think the docs are pretty clear about it's behavior.
I absolutely agree with you that there doesn't seem a use case for 0 threads. 

Out of the docs:
`HttpServer automatically starts a number of http workers, by default this number is equal to the number of logical CPUs in the system. This number can be overridden with the HttpServer::workers() method.`

Essentially when you don't use the workers method, then you get the logic cpu count. When you set it to x you get x. What I am trying to get to, is there is a use case for workers(0). Essentially indicating that 'default' shall be used as 0 would not make any sense otherwise. therefore might rather be a feature request.

 I use it personally in our configuration system, that by setting 0 for the workers config, that we translate it into the system's cpu count. I think that this having upstream would make more sense, as I see no sense on allowing to have 0 threads anyway.
> I use it personally in our configuration system, that by setting 0 for the workers config...

I think that's quite a compelling use-case for passing 0 in. PR would be welcome for this.

Fix patch:
diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md
index 067adcd656..7111fb0b4f 100644
--- a/actix-server/CHANGES.md
+++ b/actix-server/CHANGES.md
@@ -1,5 +1,11 @@
 # Changes
 
+## Unreleased
+
+### Changed
+
+* workers must be greater than 0
+
 ## [1.0.3] - 2020-05-19
 
 ### Changed
diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs
index f3f6ad86dc..8a90d598e1 100644
--- a/actix-server/src/builder.rs
+++ b/actix-server/src/builder.rs
@@ -72,8 +72,9 @@ impl ServerBuilder {
     /// Set number of workers to start.
     ///
     /// By default server uses number of available logical cpu as workers
-    /// count.
+    /// count. Workers must be greater than 0.
     pub fn workers(mut self, num: usize) -> Self {
+        assert_ne!(num, 0, "workers must be greater than 0");
         self.threads = num;
         self
     }


Test patch: