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

net: WriteMsg* returns the wrong nr of bytes sent #7645

Closed
gopherbot opened this issue Mar 26, 2014 · 14 comments
Closed

net: WriteMsg* returns the wrong nr of bytes sent #7645

gopherbot opened this issue Mar 26, 2014 · 14 comments
Milestone

Comments

@gopherbot
Copy link

by alexander.larsson:

The syscall sendmsg() returns the number of actual bytes sent, but the go wrapper
doesn't return this value. This in turn means that netFD.WriteMsg() always returns that
the number of bytes written is the the length of the passed in argument, rather than
the actual written length. This error is propagated to all callers of netFD.WriteMsg(),
which includes UnixConn.WriteMsgUnix() and UDPConn.WriteMsgUDP.
@ianlancetaylor
Copy link
Contributor

Comment 1:

The sendmsg system call always either sends the entire message or returns an error with
EMSGSIZE.  Under what circumstances can the wrong result be reported?  Can you show a
test case?

Labels changed: added repo-main.

@gopherbot
Copy link
Author

Comment 2 by alexander.larsson:

For unix sockets (SOCK_STREAM) a WriteMsgUnix() call works just like Write(). It writes
as much as it can until the socket buffer is full, then it returns the number of bytes
written. EMSGSIZE is only returned for SOCK_DGRAM sockets.
Attaching a simple example that uses UnixConn.WriteMsgUnix() with a large buffer.
Here is the output i get from it:
$ go run sendmsg.go
Result from WriteMsgUnix, bytes written: 1073741824, error: <nil>
read 219264 bytes
This is with a completely empty socket queue. If there is less space in it less would be
written.
In this particular case you can use Write() instead, but in my case I need WriteMsgUnix
because i need to send some oob data too (file descriptor passing).

@gopherbot
Copy link
Author

Comment 3 by alexander.larsson:

Somehow the attachment didn't get attached. Trying again.

Attachments:

  1. sendmsg.go (1071 bytes)

@ianlancetaylor
Copy link
Contributor

Comment 4:

Thanks for the example.  That is not good.
We can't change syscall.SendMsg, because that would break the Go 1 guarantee.  But I
guess we could introduce another function to syscall that calls sendmsg and returns the
number of bytes written.  And we could change netFD.WriteMsg to call that.

Labels changed: added release-go1.3maybe.

@mikioh
Copy link
Contributor

mikioh commented Mar 29, 2014

Comment 5:

This issue was updated by revision a7858a4.

LGTM=aram, iant
R=iant, aram, bradfitz
CC=golang-codereviews
https://golang.org/cl/81210043

@mikioh
Copy link
Contributor

mikioh commented Apr 5, 2014

Comment 6:

Status changed to Started.

@mikioh
Copy link
Contributor

mikioh commented Apr 8, 2014

Comment 7:

Status changed to New.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 8, 2014

Comment 8:

What's the status of this, Mikioh? Are we going to switch to using syscall.SendMsgN now?

@mikioh
Copy link
Contributor

mikioh commented Apr 9, 2014

Comment 9:

nope, still work on and will send a cl later; i mean, just did flush
my cl/issue queues to avoid buffer bloat. sorry for the confusion.

@gopherbot
Copy link
Author

Comment 10:

CL https://golang.org/cl/85630044 mentions this issue.

@gopherbot
Copy link
Author

Comment 11:

CL https://golang.org/cl/90170046 mentions this issue.

@mikioh
Copy link
Contributor

mikioh commented Apr 25, 2014

Comment 12:

This issue was closed by revision e419ab6.

Status changed to Fixed.

@gopherbot
Copy link
Author

Comment 13:

CL https://golang.org/cl/98790044 mentions this issue.

@mikioh
Copy link
Contributor

mikioh commented Apr 28, 2014

Comment 14:

This issue was updated by revision d873e64.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/98790044

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants