@@ -221,28 +221,24 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
221221 result := & Config {}
222222
223223 // Apply defaults for enum fields (empty/zero means not set)
224- if c .Mode == "" {
225- result .Mode = defaults .Mode
226- } else {
224+ result .Mode = defaults .Mode
225+ if c .Mode != "" {
227226 result .Mode = c .Mode
228227 }
229228
230- if c .EndpointType == "" {
231- result .EndpointType = defaults .EndpointType
232- } else {
229+ result .EndpointType = defaults .EndpointType
230+ if c .EndpointType != "" {
233231 result .EndpointType = c .EndpointType
234232 }
235233
236234 // Apply defaults for duration fields (zero means not set)
237- if c .RelaxedTimeout <= 0 {
238- result .RelaxedTimeout = defaults .RelaxedTimeout
239- } else {
235+ result .RelaxedTimeout = defaults .RelaxedTimeout
236+ if c .RelaxedTimeout > 0 {
240237 result .RelaxedTimeout = c .RelaxedTimeout
241238 }
242239
243- if c .HandoffTimeout <= 0 {
244- result .HandoffTimeout = defaults .HandoffTimeout
245- } else {
240+ result .HandoffTimeout = defaults .HandoffTimeout
241+ if c .HandoffTimeout > 0 {
246242 result .HandoffTimeout = c .HandoffTimeout
247243 }
248244
@@ -253,12 +249,11 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
253249 result .applyWorkerDefaults (poolSize )
254250
255251 // Apply queue size defaults with new scaling approach
256- if c .HandoffQueueSize <= 0 {
257- // Default: max(20x workers, PoolSize), capped by maxActiveConns or 5x pool size
258- workerBasedSize := result .MaxWorkers * 20
259- poolBasedSize := poolSize
260- result .HandoffQueueSize = util .Max (workerBasedSize , poolBasedSize )
261- } else {
252+ // Default: max(20x workers, PoolSize), capped by maxActiveConns or 5x pool size
253+ workerBasedSize := result .MaxWorkers * 20
254+ poolBasedSize := poolSize
255+ result .HandoffQueueSize = util .Max (workerBasedSize , poolBasedSize )
256+ if c .HandoffQueueSize > 0 {
262257 // When explicitly set: enforce minimum of 200
263258 result .HandoffQueueSize = util .Max (200 , c .HandoffQueueSize )
264259 }
@@ -277,9 +272,8 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
277272 result .HandoffQueueSize = 2
278273 }
279274
280- if c .PostHandoffRelaxedDuration <= 0 {
281- result .PostHandoffRelaxedDuration = result .RelaxedTimeout * 2
282- } else {
275+ result .PostHandoffRelaxedDuration = result .RelaxedTimeout * 2
276+ if c .PostHandoffRelaxedDuration > 0 {
283277 result .PostHandoffRelaxedDuration = c .PostHandoffRelaxedDuration
284278 }
285279
@@ -288,9 +282,8 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
288282 result .LogLevel = c .LogLevel
289283
290284 // Apply defaults for configuration fields
291- if c .MaxHandoffRetries <= 0 {
292- result .MaxHandoffRetries = defaults .MaxHandoffRetries
293- } else {
285+ result .MaxHandoffRetries = defaults .MaxHandoffRetries
286+ if c .MaxHandoffRetries > 0 {
294287 result .MaxHandoffRetries = c .MaxHandoffRetries
295288 }
296289
@@ -329,12 +322,12 @@ func (c *Config) applyWorkerDefaults(poolSize int) {
329322 poolSize = 10 * runtime .GOMAXPROCS (0 )
330323 }
331324
332- if c . MaxWorkers == 0 {
333- // When not set: min(poolSize/2, max(10, poolSize/3)) - balanced scaling approach
334- c .MaxWorkers = util .Min (poolSize / 2 , util .Max (10 , poolSize / 3 ))
335- } else {
325+ // When not set: min(poolSize/2, max(10, poolSize/3)) - balanced scaling approach
326+ originalMaxWorkers := c . MaxWorkers
327+ c .MaxWorkers = util .Min (poolSize / 2 , util .Max (10 , poolSize / 3 ))
328+ if originalMaxWorkers != 0 {
336329 // When explicitly set: max(poolSize/2, set_value) - ensure at least poolSize/2 workers
337- c .MaxWorkers = util .Max (poolSize / 2 , c . MaxWorkers )
330+ c .MaxWorkers = util .Max (poolSize / 2 , originalMaxWorkers )
338331 }
339332
340333 // Ensure minimum of 1 worker (fallback for very small pools)
0 commit comments