Skip to content

Switch goroutines for contexts in packetconn - #395

Open
noboruma wants to merge 1 commit into
pion:mainfrom
noboruma:remove-goroutines-packetconn
Open

Switch goroutines for contexts in packetconn#395
noboruma wants to merge 1 commit into
pion:mainfrom
noboruma:remove-goroutines-packetconn

Conversation

@noboruma

Copy link
Copy Markdown

Remove goroutines in Write/Read hot paths from packetconn

@noboruma
noboruma force-pushed the remove-goroutines-packetconn branch from 80b0c3c to 5ce1626 Compare August 30, 2026 13:35
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.41176% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.38%. Comparing base (65248b8) to head (6f42564).

Files with missing lines Patch % Lines
netctx/packetconn.go 79.41% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
- Coverage   84.45%   84.38%   -0.07%     
==========================================
  Files          41       41              
  Lines        3416     3388      -28     
==========================================
- Hits         2885     2859      -26     
  Misses        393      393              
+ Partials      138      136       -2     
Flag Coverage Δ
go 84.38% <79.41%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@noboruma
noboruma force-pushed the remove-goroutines-packetconn branch from 5ce1626 to 306a259 Compare August 30, 2026 13:41
@noboruma
noboruma requested a review from JoTurk August 30, 2026 13:45

@JoTurk JoTurk 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.

Looks great thank you, I also tested it locally :)

Just 2 comments and one nit.

Comment thread netctx/packetconn.go Outdated
Comment thread netctx/packetconn.go Outdated
Comment thread netctx/packetconn.go Outdated
defer cancel()

detachDeadline := context.AfterFunc(combinedCtx, func() {
_ = p.nextConn.SetReadDeadline(veryOld)

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.

nit: maybe we shouldn't ignore deadline errors?

@noboruma noboruma Aug 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

So actually I gave that one some thoughts because it was specifically handled in the previous impl. My conclusion here is that failing at the SetReadDeadline stage should only happen if the connection is closed already. So we don't really care at that stage. Now this holds true for standard implementations, in the case the connection was not closed and the SetReadDeadline truly failed (which in theory should never happen unless the underlying implementation is buggy) we would be in much more trouble since that operation could hang forever (which was also the case in the previous impl since we only returned the err after the read finished).

I think a better alternative here would be to simply panic in case of error so it gives a chance to recover?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually realized we cannot do that properly because AfterFunc would panic on a different goroutine - reworking the whole SetReadDeadline instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Here I am opting for a closure of the whole connection so that we avoid hanging

@noboruma
noboruma force-pushed the remove-goroutines-packetconn branch 16 times, most recently from 631b858 to 6384588 Compare August 31, 2026 05:19
@noboruma
noboruma requested a review from JoTurk August 31, 2026 09:35
@noboruma
noboruma force-pushed the remove-goroutines-packetconn branch 2 times, most recently from 34c0b6d to 434e560 Compare September 2, 2026 04:20
@noboruma
noboruma force-pushed the remove-goroutines-packetconn branch from 434e560 to 6f42564 Compare September 11, 2026 13:32
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