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

Comments

Projects
None yet
5 participants
@gopherbot
Copy link

commented Mar 26, 2014

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

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2014

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

This comment has been minimized.

Copy link
Author

commented Mar 26, 2014

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

This comment has been minimized.

Copy link
Author

commented Mar 26, 2014

Comment 3 by alexander.larsson:

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

Attachments:

  1. sendmsg.go (1071 bytes)
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2014

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2014

Comment 6:

Status changed to Started.

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Apr 8, 2014

Comment 7:

Status changed to New.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Apr 8, 2014

Comment 8:

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Apr 10, 2014

Comment 10:

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

This comment has been minimized.

Copy link
Author

commented Apr 25, 2014

Comment 11:

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

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2014

Comment 12:

This issue was closed by revision e419ab6.

Status changed to Fixed.

@gopherbot

This comment has been minimized.

Copy link
Author

commented Apr 28, 2014

Comment 13:

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

This comment has been minimized.

Copy link
Contributor

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

@rsc rsc removed the release-go1.3maybe label 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.
You can’t perform that action at this time.