Skip to content

identify_license: fix send on closed channel in v2 backend - #76

Open
wagoodman wants to merge 1 commit into
google:mainfrom
wagoodman:fix/identify-license-send-on-closed-channel
Open

wagoodman wants to merge 1 commit into
google:mainfrom
wagoodman:fix/identify-license-send-on-closed-channel

Conversation

@wagoodman

Copy link
Copy Markdown

ClassifyLicenses closes the task channel once the wait group drains, but each worker's deferred cleanup calls wg.Done() before task <- true. The closer goroutine can run between the two, and the final send panics with send on closed channel. Nothing ranges over task, so it is now left open. #21 fixed the same panic in the v1 backend, but the v2 copy still had it.

Also fixed in the same backend:

  • ClassifyLicensesWithContext returned as soon as ctx was done but left the classification running in the background, racing on the named return, leaking the goroutine, and appending results into later calls on the same backend. ctx is now checked in the dispatch loop: once it is done no new files start, in-flight files finish, and the call returns ctx.Err(). Nothing outlives the call, though it can return slightly after the deadline.
  • GetResults read b.results without the lock. It now reads under the lock and returns a copy.

@google-cla

google-cla Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

`ClassifyLicenses` closes the `task` channel once the wait group drains, but each worker's deferred cleanup calls `wg.Done()` before `task <- true`. The closer goroutine can run between the two, and the final send panics with `send on closed channel`. Nothing ranges over `task`, so it is now left open. google#21 fixed the same panic in the v1 backend, but the v2 copy still had it.

Also fixed in the same backend:

- `ClassifyLicensesWithContext` returned as soon as ctx was done but left the classification running in the background, racing on the named return, leaking the goroutine, and appending results into later calls on the same backend. ctx is now checked in the dispatch loop: once it is done no new files start, in-flight files finish, and the call returns `ctx.Err()`. Nothing outlives the call, though it can return slightly after the deadline.
- `GetResults` read `b.results` without the lock. It now reads under the lock and returns a copy.

Signed-off-by: Alex Goodman <wagoodman@gmail.com>
@wagoodman
wagoodman force-pushed the fix/identify-license-send-on-closed-channel branch from bc0b185 to 37ddd00 Compare October 2, 2026 15:20
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.

1 participant