Skip to content

Conversation

Copy link

Copilot AI commented Dec 30, 2025

Problem

Race condition between worker goroutines adding tasks and main goroutine closing the task channel causes panic when processing deep search results.

Failure sequence:

Worker: processTask() → wg.Done() → AddTask() (tries to send)
Main:   wg.Wait() completes → closeCH() → closes taskCh
Worker: panic: send on closed channel

Changes

  • Added closed flag to EnJob struct to track channel lifecycle
  • Modified AddTask() and reTaskQueue(): Check closed flag under lock, increment wait group, release lock, then send to channel
  • Modified closeCH(): Set closed flag before closing channels, prevent double-close

Safety

Wait group increment happens before lock release. Since closeCH() is only called after wg.Wait() completes, the channel is guaranteed open during send:

func (q *EnJob) AddTask(task DeepSearchTask) {
    q.mu.Lock()
    if q.closed {
        q.mu.Unlock()
        return
    }
    q.wg.Add(1)  // Prevents channel close
    q.mu.Unlock()
    q.taskCh <- task  // Safe: wg blocks closeCH()
}

Lock is released before channel send to prevent deadlock when channel is full.

Original prompt

This section details on the original issue you should resolve

<issue_title>panic: send on closed channel</issue_title>
<issue_description>搜索比如温州大学时会有这个报错
panic: send on closed channel

goroutine 32 [running]:
github.com/wgpsec/ENScan/runner.(*EnJob).AddTask(0xc00021c1b0, {{{0xc000350a20, 0x24}, {0xc0005a2887, 0xe}, {0xc00018aa10, 0x67}, 0x2, {0xf84131, 0x6}, ...}, ...})
/home/runner/work/ENScan_GO/ENScan_GO/runner/bean.go:134 +0x45
github.com/wgpsec/ENScan/runner.(*EnJob).processTask(0xc00021c1b0, {{{0xc000031320, 0x24}, {0xc00056c481, 0xe}, {0xc0006104b0, 0x4f}, 0x1, {0xf84131, 0x6}, ...}, ...})
/home/runner/work/ENScan_GO/ENScan_GO/runner/enscan.go:171 +0x487
github.com/wgpsec/ENScan/runner.(*EnJob).StartWorkers.func1()
/home/runner/work/ENScan_GO/ENScan_GO/runner/bean.go:150 +0xa6
created by github.com/wgpsec/ENScan/runner.(*EnJob).StartWorkers in goroutine 16
/home/runner/work/ENScan_GO/ENScan_GO/runner/bean.go:143 +0x4f</issue_description>

Comments on the Issue (you are @copilot in this section)

@keac 请师傅详细列下查询的命令和使用程序的版本号

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 30, 2025
Copilot AI and others added 5 commits December 30, 2025 02:19
Co-authored-by: keac <16091665+keac@users.noreply.github.com>
Co-authored-by: keac <16091665+keac@users.noreply.github.com>
Co-authored-by: keac <16091665+keac@users.noreply.github.com>
Co-authored-by: keac <16091665+keac@users.noreply.github.com>
Co-authored-by: keac <16091665+keac@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic error on sending to closed channel Fix race condition causing "panic: send on closed channel" Dec 30, 2025
Copilot AI requested a review from keac December 30, 2025 02:28
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.

panic: send on closed channel

2 participants