Skip to content

Fix rand.Seed initialization and data races in progress bars - #6

Open
msarg44 wants to merge 1 commit into
L-codes:masterfrom
msarg44:fix/rand-seed-and-data-race
Open

Fix rand.Seed initialization and data races in progress bars#6
msarg44 wants to merge 1 commit into
L-codes:masterfrom
msarg44:fix/rand-seed-and-data-race

Conversation

@msarg44

@msarg44 msarg44 commented Aug 12, 2026

Copy link
Copy Markdown

Two fixes for correctness issues:

1. Add rand.Seed(time.Now().UnixNano()) in init()

The project declares go 1.16 and uses rand.Shuffle() in IPCIDR() and IPWildcard() for non-sequential mode. Go 1.16–1.19 require explicit seeding via rand.Seed() — without it, the shuffle produces identical ordering every run, defeating the purpose of !seqMode.

2. Fix data races in progress bar routines

ProgressBar() and RejectAllOpenProgressBar() read shared counters (doneCount, hostUpCount, openCount, hostDiscard, stopRejectAllOpenProgressBar) without holding the mutex that protects writes to these variables in worker goroutines. This is a data race per the Go memory model.

Changes:

  • ProgressBar(): local copies of counters under mutex lock before logging
  • RejectAllOpenProgressBar(): same treatment for counters, plus stopRejectAllOpenProgressBar reads under mutex

Both fixes verified to compile with go 1.16 through current Go versions.

- Add rand.Seed(time.Now().UnixNano()) in init() to ensure
  random host/port order when !seqMode (Go 1.16-1.19
  require explicit seeding; without it, shuffle produces
  identical results every run)

- Fix data races in ProgressBar() and RejectAllOpenProgressBar()
  where shared counters (doneCount, hostUpCount, openCount,
  hostDiscard, stopRejectAllOpenProgressBar) were read without
  holding the mutex that protects their writes
@L-codes

L-codes commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Thanks for submitting, but the counting variable name will simply retain the original name to improve readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants