Skip to content

Fix send on closed channel panic in SSE stream handlers#6456

Merged
6543 merged 10 commits into
woodpecker-ci:mainfrom
hhamalai:main
Apr 20, 2026
Merged

Fix send on closed channel panic in SSE stream handlers#6456
6543 merged 10 commits into
woodpecker-ci:mainfrom
hhamalai:main

Conversation

@hhamalai

Copy link
Copy Markdown
Contributor

Instead of explicitly closing channels which leads to concurrency issues with channels being used after close, allow channels to be GC'ed.

Remove the recover block that was previously catching&masking the panics in the LogStreamSSE. EventStreamSSE was missing the same

fixes: #6454

hhamalai and others added 2 commits April 16, 2026 13:53
Instead of explicitly closing channels which leads to concurrency issues
with channels being used after close, allow channels to be GC'ed.

Remove the recover block that was previously catching&masking the panics in the LogStreamSSE. EventStreamSSE was missing the same

fixes: woodpecker-ci#6454

@utafrali utafrali left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core fix is correct and is a genuine improvement: removing close(eventChan) / close(logChan) from defers eliminates the send-on-closed-channel panics, the updated selects properly unblock on context cancellation (better than the old default-fallthrough pattern), and adding close(batches) fixes a pre-existing goroutine leak in LogStreamSSE. The main concerns are test fragility (timing-based sync) and a potential last-entries-lost race when a log stream ends naturally before the inner goroutine drains its buffer.

Comment thread server/api/stream_test.go Outdated
Comment thread server/api/stream.go
Comment thread server/api/stream_test.go
Comment thread server/api/stream_test.go Outdated
@woodpecker-bot

This comment was marked as off-topic.

@6543

6543 commented Apr 16, 2026

Copy link
Copy Markdown
Member

now I dont know why there are tow pulls working on the same issue by the same people either authored or reviewed!?!?

-> #6455

@hhamalai

hhamalai commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

now I dont know why there are tow pulls working on the same issue by the same people either authored or reviewed!?!?

-> #6455

How you wish to proceed @6543 I suspected the another PR was agent generated as the unit tests still weren't testing against the right fix, and the further commits introduced more regression. Happy to close this one, as the other PR has a good start.

@6543

6543 commented Apr 16, 2026

Copy link
Copy Markdown
Member

well i prevere human interaction, if llms are used is fine as long as it's just a tool, the contributor has to own its mistakes and also understand the code ...

I will look into both pulls and then decide what to take from what ... give me time to do so :)

@6543 6543 added bug Something isn't working server labels Apr 20, 2026
@codecov

codecov Bot commented Apr 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.32%. Comparing base (dc11182) to head (0cd7b84).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/api/stream.go 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6456      +/-   ##
==========================================
+ Coverage   40.87%   41.32%   +0.44%     
==========================================
  Files         431      431              
  Lines       28821    28815       -6     
==========================================
+ Hits        11781    11907     +126     
+ Misses      15987    15840     -147     
- Partials     1053     1068      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@6543 6543 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

@6543 6543 enabled auto-merge (squash) April 20, 2026 22:16
@6543 6543 changed the title fix: fixes send on closed channel panic in SSE stream handlers Fix send on closed channel panic in SSE stream handlers Apr 20, 2026
@6543 6543 merged commit 27ed7da into woodpecker-ci:main Apr 20, 2026
7 checks passed
This was referenced Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

woodpecker server panics & crashes at times

4 participants