Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blocking write mode for association #356

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Add blocking write mode for association #356

merged 1 commit into from
Dec 9, 2024

Conversation

cnderrauber
Copy link
Member

@cnderrauber cnderrauber commented Nov 26, 2024

Block write is useful for cases like sfu to forward reliable message between clients and detach the data channel to use it as normal golang connections. The default behavior is still non-block mode and the user need to enable block mode by the config. Will also add an SettingEngine option to pion/webrtc for this.

Relates to #77 and #314

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 81.58%. Comparing base (ce7e8bc) to head (99301e5).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
stream.go 83.33% 4 Missing ⚠️
association.go 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #356      +/-   ##
==========================================
- Coverage   81.66%   81.58%   -0.08%     
==========================================
  Files          51       51              
  Lines        4341     4383      +42     
==========================================
+ Hits         3545     3576      +31     
- Misses        654      663       +9     
- Partials      142      144       +2     
Flag Coverage Δ
go 81.58% <90.00%> (-0.08%) ⬇️
wasm 66.62% <24.00%> (-0.53%) ⬇️

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

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

Block write is useful for cases like sfu to
forward reliab message between clients and
detach the data channel to use it as normal
golang connections.
@Sean-Der
Copy link
Member

Love this feature! Great idea putting it behind a SettingEngine option.

Would it be possible to implement this by watching/peeking at a.pendingQueue.getNumBytes() + a.inflightQueue.getNumBytes()? Add some kind of notifier/callback that gets fired when it goes to zero.

It would allow us to keep the internals a lot simpler.

@cnderrauber
Copy link
Member Author

Love this feature! Great idea putting it behind a SettingEngine option.

Would it be possible to implement this by watching/peeking at a.pendingQueue.getNumBytes() + a.inflightQueue.getNumBytes()? Add some kind of notifier/callback that gets fired when it goes to zero.

It would allow us to keep the internals a lot simpler.

It will reduce the throughput if we watch the pending/inflight bytes to become zero that every write needs to wait for previous one to be acked by remote peer, it is also not identical to the net.conn's write method which returns after copy the data to the socket buffer.

Copy link

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

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

lgtm!

a.lock.Unlock()
select {
case <-ctx.Done():
return ctx.Err()

Choose a reason for hiding this comment

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

how should this error be handled? does this bubble up to the app level or it is all handled internally? Am curious about how this affects reliable transmission mode and if app need to retry send?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will return to upper application, when WriteSCTP returns error, it means the data has not been sent (incorrect state or deadline timeout) so no retransmission here, the retransmission only works for sent messages (write operation succeeded).

Choose a reason for hiding this comment

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

got it, wondering if the application is supposed to try Write again?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should do that if blocking mode is enabled, like other connections. The default behavior is still unblock mode

Choose a reason for hiding this comment

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

sounds good, thank you 🙏

@Sean-Der
Copy link
Member

@cnderrauber @boks1971 Push back if you disagree, but I think we should have Write drive and not create these single purpose points of communication.

This would be a deeper change. I think it will be easier to maintain/follow. As more gets added to the code base it gets harder to reason about and eventually the complexity makes everyone want to start over.

@cnderrauber
Copy link
Member Author

@Sean-Der It's a patch for blocking write based on currently read/write loop, the feature is useful for flow control in sfu forwarding reliable message and other people request it for long time. I think the change is easy to understand that the queueBuffer works as a ongoing write packet buffer in block mode and other write needs to wait for it drained.

I agree the write drive will make the write more straghtforward but we might still need buffer/notify to implement non-block writing if we don't want to break the API. So it is more like a v2 feature, what do you think?

@cnderrauber cnderrauber merged commit abb6bea into master Dec 9, 2024
13 checks passed
@cnderrauber cnderrauber deleted the block_write branch December 9, 2024 08:02
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.

3 participants