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

Buffer garbling on write #2

Open
maxless opened this issue Aug 24, 2022 · 1 comment
Open

Buffer garbling on write #2

maxless opened this issue Aug 24, 2022 · 1 comment

Comments

@maxless
Copy link

maxless commented Aug 24, 2022

Since you spawn a goroutine for each send, if the buffers are reused by the application after sending (like in KCP library we use), they will get garbled potentially before sending. I suggest either noting in the documentation that one needs to copy buffers before calling WriteTo() or adding an explicit copy before making a goroutine:

func (c *packetConn) WriteTo(bts []byte, addr net.Addr) (int, error) {
...
  p := make([]byte, len(bts))
  copy(p, bts)
  go func() {
...

https://github.com/cevatbarisyilmaz/lossy/blob/master/packet_conn.go#L69

conn.go has the same issue.

@cevatbarisyilmaz
Copy link
Owner

Hey, thanks for raising the issue. Would you like to create a pr to fix it? Adding explicit copy looks good to me.

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

No branches or pull requests

2 participants