Skip to content

Buffer garbling on write #2

@maxless

Description

@maxless

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions