mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Fix negative parallelism and negative semaphore (#23902)
* Throw an error when parallelism <=0 * Panic in case of negative semaphore
This commit is contained in:
parent
851e6dcdbb
commit
b956e8ef35
@ -138,7 +138,17 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
|
|||||||
// Determine parallelism, default to 10. We do this both to limit
|
// Determine parallelism, default to 10. We do this both to limit
|
||||||
// CPU pressure but also to have an extra guard against rate throttling
|
// CPU pressure but also to have an extra guard against rate throttling
|
||||||
// from providers.
|
// from providers.
|
||||||
|
// We throw an error in case of negative parallelism
|
||||||
par := opts.Parallelism
|
par := opts.Parallelism
|
||||||
|
if par < 0 {
|
||||||
|
diags = diags.Append(tfdiags.Sourceless(
|
||||||
|
tfdiags.Error,
|
||||||
|
"Invalid parallelism value",
|
||||||
|
fmt.Sprintf("The parallelism must be a positive value. Not %d.", par),
|
||||||
|
))
|
||||||
|
return nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
if par == 0 {
|
if par == 0 {
|
||||||
par = 10
|
par = 10
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ type Semaphore chan struct{}
|
|||||||
// NewSemaphore creates a semaphore that allows up
|
// NewSemaphore creates a semaphore that allows up
|
||||||
// to a given limit of simultaneous acquisitions
|
// to a given limit of simultaneous acquisitions
|
||||||
func NewSemaphore(n int) Semaphore {
|
func NewSemaphore(n int) Semaphore {
|
||||||
if n == 0 {
|
if n <= 0 {
|
||||||
panic("semaphore with limit 0")
|
panic("semaphore with limit <=0")
|
||||||
}
|
}
|
||||||
ch := make(chan struct{}, n)
|
ch := make(chan struct{}, n)
|
||||||
return Semaphore(ch)
|
return Semaphore(ch)
|
||||||
|
Loading…
Reference in New Issue
Block a user